Three-dimensional shading method, apparatus, and computing device, and storage medium

ABSTRACT

In a three-dimensional shading method, a computing device obtains position information and intensity of at a light source in a target space. The computing device determines, based on the position information and the intensity of the light source, illumination information corresponding to each surface of a three-dimensional object in the target space under illumination of the light source. For each surface, the illumination information corresponding to the surface includes one or more layers of illumination information that reflect illumination information of each position point on the surface under illumination of the light source. The computing device then provides the illumination information of the multiple surfaces of the three-dimensional object to a device that performs shading processing on the target space.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of International Application No.PCT/CN2021/102806, filed on Jun. 28, 2021, which claims priority toChinese Patent Application No. 202010896298.4, filed on Aug. 31, 2020,which claims priority to Chinese Patent Application No. 202110649436.3,filed on Jun. 10, 2021. All of the aforementioned priority applicationsare hereby incorporated by reference in their entirety.

TECHNICAL FIELD

This application relates to the field of image rendering, and inparticular, to a three-dimensional shading method, apparatus, andcomputing device, and a storage medium.

BACKGROUND

Currently, a three-dimensional object is included in many scenarios. Thethree-dimensional object includes a grid formed by geometry, and thegeometry is an element formed by a polygon in a three-dimensional model,for example, a point, a line, a triangle, or a polygon. For example, aplurality of triangles form a three-dimensional object. When shadingprocessing is performed on the three-dimensional object in a process ofrendering the three-dimensional object in three-dimensional space, a raytracing method is usually used during the shading processing.Specifically, when the ray tracing method is used, a shading devicetracks, by using a set position of a light source, a quantity of lightrays of the light source, and a light direction, a light ray emittedfrom eyes, and shades the three-dimensional object. Subsequently, thethree-dimensional object may be displayed based on a shading result.

When the ray tracing method is used, because the light ray emitted fromthe eyes is tracked, when re-shading is caused by a change of anobserver position or a viewing angle of an observer, light casting in ashading process needs to be recalculated. As a result, the amount ofcalculation is large.

SUMMARY

This application provides a three-dimensional shading method, apparatus,and computing device, and a storage medium, to reduce a calculationamount of a shading device.

According to a first aspect, this application provides athree-dimensional shading method, where the method includes: obtainingposition information and an intensity of at least one light source intarget space; determining, based on the position information and theintensity of the at least one light source, at least one group ofillumination information corresponding to each surface of athree-dimensional object in the target space under illumination of theat least one light source, where for any surface, a first group ofillumination information corresponding to the surface includes one ormore layers of illumination information, and the one or more layers ofillumination information reflect illumination information of eachposition point on the surface under illumination of a light source towhich the first group of illumination information belongs; and providingthe at least one group of illumination information for a device thatperforms shading processing on the target space.

In the solution shown in this application, the method may be performedby a server. The server may obtain the position information and theintensity of the at least one light source that are set by a personskilled in the art when drawing the target space. The positioninformation of the light source is used to indicate a position of thelight source in the target space. The intensity of the light source maybe represented by using a color of the light source, or may berepresented by using A watts per square meter, where A is a value of theintensity of the light source. For each light source, the server maydetermine, based on the position information and the intensity of thelight source and position information of each three-dimensional objectin the target space, a group of illumination information correspondingto each surface of each three-dimensional object in the target spaceunder illumination of the light source, that is, obtain a group ofillumination information corresponding to each surface of thethree-dimensional object in the target space under illumination of thelight source, where the group of illumination information includes theone or more layers of illumination information. The server may determinedevices that perform shading processing on the target space, and sendthe at least one group of illumination information in the target spaceto these devices.

In this way, for target space, the server may calculate illuminationinformation once, and provide the illumination information for thedevice (subsequently referred to as a shading device) that performsshading processing on the target space. Therefore, the shading devicemay perform shading processing on the target space based on a viewingangle and an observer position determined by the shading device and theillumination information provided by the server. In this way, even ifthe shading device obtains that the viewing angle and/or the observerposition change/changes, the illumination information does not need tobe re-determined. Therefore, a processing resource of the shading devicecan be saved.

In a possible implementation, the method further includes: obtaininglight ray information of the light source, where the light rayinformation includes a quantity of light rays and a light direction; andthe determining, based on the position information and the intensity ofthe at least one light source, at least one group of illuminationinformation corresponding to each surface of a three-dimensional objectin the target space under illumination of the at least one light sourceincludes: determining scattering information of each surface of thethree-dimensional object in the target space with a light ray of the atleast one light source based on the intensity, the position information,and the light ray information of the at least one light source; anddetermining, based on the scattering information of each surface of thethree-dimensional object, the at least one group of illuminationinformation corresponding to each surface of the three-dimensionalobject under illumination of the at least one light source.

For a first surface of the three-dimensional object under illuminationof any one light source, scattering information of the first surfaceincludes an intensity, a direction, and a number of bounces of anincident light ray at each position point on the first surface, orincludes an intensity, a direction, and a number of bounces of areflection light ray at each position point on the first surface.

In the solution shown in this application, the server may obtain lightray information of a light source, where the light ray information ofthe light source may include a quantity of light rays and a lightdirection of the light source, the quantity of light rays is a quantityof light rays emitted by the light source, and the light direction is anangle at which each light ray is emitted from the light source. Theserver respectively determines a group of illumination informationcorresponding to each surface of a three-dimensional object underillumination of each light source. Specifically, for any one lightsource, the server may determine scattering information of each surfaceof each three-dimensional object in target space with a light ray of thelight source based on the intensity of the light source, positioninformation of the light source, the light ray information of the lightsource, and the position information of the three-dimensional object inspace. When determining the scattering information, the serverdetermines the scattering information by using a ray casting algorithmin ray tracing. Then, the server may determine, by using the scatteringinformation of each surface of each three-dimensional object, at leastone group of illumination information corresponding to each surface ofeach three-dimensional object under illumination of at least one lightsource. In this way, the corresponding at least one group ofillumination information under illumination of the at least oneillumination may be determined based on the scattering information.

In a possible implementation, the determining, based on the scatteringinformation of each surface of the three-dimensional object, the atleast one group of illumination information corresponding to eachsurface of the three-dimensional object under illumination of the atleast one light source includes: separately superposing, for a firstsurface of the three-dimensional object in the target space, intensitiesand directions of light rays that have a same number of bounces and thatare in scattering information corresponding to the first surface underillumination of a target light source in the at least one light source,to obtain a superposition intensity and a superposition direction ofrays of each number of bounces and corresponding to the first surface;and determining, based on the superposition intensity and thesuperposition direction of the rays of each number of bounces, a groupof illumination information corresponding to the first surface underillumination of the target light source.

In the solution shown in this application, under illumination of thetarget light source, the scattering information corresponding to thefirst surface includes an intensity, a direction, and a source of anincident light ray at each position point on the first surface, and thesource records a number of bounces when the light ray is bounced on thefirst surface after being emitted from the light source. The server maysuperpose directions of incident light rays having a same number ofbounces at each position point on the first surface, to obtain adirection of the incident light ray at each position point, andsuperpose intensities of the incident light rays having the same numberof bounces at each position point, to obtain a superposition intensityof the incident light ray at each position point. For the first surface,the server determines the superposition intensity and the superpositiondirection of the incident light ray having each number of bounces as agroup of illumination information of the first surface underillumination of the target light source. In the group of illuminationinformation, each layer of illumination information is the superpositionintensity and the superposition direction of the incident light rayhaving each number of bounces. Alternatively, under illumination of thetarget light source, the scattering information corresponding to thefirst surface includes an intensity, a direction, and a source of areflection light ray at each position point on the first surface, andthe source records a number of bounces when the light ray is bounced onthe first surface after being emitted from the light source. The servermay superpose directions of reflection light rays having a same numberof bounces at each position point on the first surface, to obtain asuperposition direction of the reflection light ray at each positionpoint, and superpose intensities of the reflection light rays having thesame number of bounces at each position point, to obtain a superpositionintensity of the reflection light ray at each position point. For thefirst surface, the server determines the superposition intensity and thesuperposition direction of the reflection light ray having each numberof bounces as a group of illumination information of the first surfaceunder illumination of the target light source. In the group ofillumination information, each layer of illumination information is thesuperposition intensity and the superposition direction of thereflection light ray having each number of bounces. In this way,illumination information of each surface can be accurately determined bylight casting.

In a possible implementation, an intensity and a direction of a lightray in the scattering information corresponding to the first surfaceunder illumination of the target light source are respectively anincident intensity and an incident direction of a light ray incident tothe first surface; or an intensity and a direction of a light ray in thescattering information corresponding to the first surface underillumination of the target light source are respectively a reflectionintensity and a reflection direction of a light ray reflected from thefirst surface.

In a possible implementation, the determining, based on the scatteringinformation of each surface of the three-dimensional object, the atleast one group of illumination information corresponding to eachsurface of the three-dimensional object under illumination of the atleast one light source includes: for a first surface of thethree-dimensional object, determining, in scattering informationcorresponding to the first surface under illumination of a target lightsource, an intensity and a direction of a light ray that belongs to eachincident range and that is in light rays incident to each positionpoint; and determining, based on a superposition intensity and asuperposition direction of the light ray that is in each incident rangeand that corresponds to each position point, a group of illuminationinformation corresponding to the first surface under illumination of thetarget light source; or for a first surface of the three-dimensionalobject, determining, in scattering information corresponding to thefirst surface under illumination of a target light source, an intensityand a direction of a light ray that belongs to each reflection range andthat is in light rays emitted from each position point; and determining,based on a superposition intensity and the superposition direction ofthe light ray that is in each reflection range and that corresponds toeach position point, a group of illumination information correspondingto the first surface under illumination of the target light source.

In the solution shown in this application, each light source is dividedinto a plurality of incident ranges based on an incident angle, anddivision of the incident ranges may be set based on an actualrequirement. For a target position point on the first surface of thethree-dimensional object, the target position point is any positionpoint on the first surface. In scattering information corresponding tothe first surface under illumination of the target light source, anintensity and a direction of a light ray that belongs to each incidentrange and that is in light rays incident to the target position pointare determined based on an incident angle in the incident range. For afirst incident range in the incident ranges, intensities of light raysthat belong to the first incident range are superposed to obtain asuperposition intensity of a light ray at the target position point, anddirections of the light rays that belong to the first incident range aresuperposed to obtain a superposition direction of the light ray at thetarget position point. In this manner, the superposition intensity andthe superposition direction of the light ray at each position point onthe first surface in each incident range are obtained.

Alternatively, each light source is divided into a plurality ofreflection ranges based on a reflection angle, and division of thereflection ranges may be set based on an actual requirement. For atarget position point on the first surface of the three-dimensionalobject, in scattering information corresponding to the first surfaceunder illumination of the target light source, an intensity and adirection of a light ray that belongs to each reflection range and thatis in light rays emitted from the target position point are determinedbased on a reflection angle in the reflection range. For a firstreflection range in the reflection ranges, intensities of light raysthat belong to the first reflection range are superposed to obtain asuperposition intensity of a light ray at the target position point, anddirections of the light rays that belong to the first reflection rangeare superposed to obtain a superposition direction of the light ray atthe target position point. In this manner, the superposition intensityand the superposition direction of the light ray at each position pointon the first surface in each reflection range are obtained.

In this way, illumination information can be more flexible throughdivision of an angle range.

According to a second aspect, this application provides athree-dimensional shading method, where the method includes: obtainingat least one group of illumination information corresponding to eachsurface of a three-dimensional object in target space under illuminationof at least one light source, where for any surface, a first group ofillumination information corresponding to the surface includes one ormore layers of illumination information, and the one or more layers ofillumination information reflect illumination information of eachposition point on the surface under illumination of a light source towhich the first group of illumination information belongs; obtaining anobserver position and a viewing angle of an observer; and performing, inscreen space, shading processing on the three-dimensional object in thetarget space based on illumination information corresponding to eachsurface of the three-dimensional object in the target space underillumination of a current light source, the observer position, and theviewing angle.

In the solution shown in this application, the method may be performedby a shading device, and the screen space is two-dimensional space, andis coordinate space of a 2D image generated during 3D rendering. Theshading device may receive at least one group of illuminationinformation that corresponds to each surface of each three-dimensionalobject in the target space under illumination of the at least one lightsource and that is sent by a server, and then store the at least onegroup of illumination information. Alternatively, the shading devicedetermines at least one group of illumination information correspondingto each surface of each three-dimensional object in the target spaceunder illumination of the at least one light source, and stores the atleast one group of illumination information. In different scenarios, theshading device obtains the observer position of the observer indifferent manners. For example, in a game scenario, an initial positionis preset. An observer (that is, a game player) controls a player byusing a game lever to move in target space. The shading devicedetermines movement information of a current game lever relative to theinitial position, and determines a position of a current player, thatis, obtains the observer position of the observer. The observer positionis a position of the observer in a world coordinate system. The shadingdevice may detect a line-of-sight direction of eyes, to obtain a viewingangle of the observer. Then, the shading device may determine thecurrent light source in the target space. The shading device may performshading processing on the three-dimensional object in the target spacebased on illumination information and material information of eachsurface of each three-dimensional object under illumination of thecurrent light source, position information of each three-dimensionalobject, geometric information of each three-dimensional object, and aposition coordinate of each three-dimensional object in an observercoordinate system, to obtain a total shading result of each surface ofthe three-dimensional object. In this way, because illuminationinformation of each three-dimensional object in the target space can beobtained, even if the observer position and the viewing angle change,the shading device may directly re-perform shading processing on thetarget space based on the illumination information in the target space,and the illumination information does not need to be recalculated in ashading process. Therefore, a processing resource of the shading devicecan be saved.

In a possible implementation, the performing, in screen space, shadingprocessing on the three-dimensional object in the target space based onillumination information corresponding to each surface of thethree-dimensional object in the target space under illumination of acurrent light source, the observer position, and the viewing angleincludes: if there are a plurality of the current light sources,separately performing, under illumination of any one light source of thecurrent light sources, shading processing on each surface of thethree-dimensional object based on illumination information correspondingto each surface of the three-dimensional object under illumination ofthe light source, the observer position, and the viewing angle, toobtain a shading result of each surface of the three-dimensional objectin the screen space under illumination of the light source; andaccumulating shading results of each surface of the three-dimensionalobject in the screen space under illumination of the current lightsources, to obtain a total shading result of each surface of thethree-dimensional object in the screen space.

In the solution shown in this application, the shading device maydetermine a shading result of each surface of the three-dimensionalobject under illumination of each current light source. Then, for anysurface, the shading device may accumulate all shading results of thesurface to obtain a total shading result of the surface. In this way,shading can also be implemented in the case of a plurality of lightsources.

In a possible implementation, under illumination of any one light sourceof current light sources, the separately performing, under illuminationof any one light source of the current light sources, shading processingon each surface of the three-dimensional object based on illuminationinformation corresponding to each surface of the three-dimensionalobject under illumination of the light source, the observer position,and the viewing angle, to obtain a shading result of each surface of thethree-dimensional object in the screen space under illumination of thelight source includes: under illumination of any one light source of thecurrent light sources, if a first surface of the three-dimensionalobject in the target space corresponds to one layer of illuminationinformation, obtaining, based on the layer of illumination informationcorresponding to the first surface, the observer position, and theviewing angle, a shading result of the first surface in the screen spaceunder illumination of the light source; or if the first surface of thethree-dimensional object corresponds to a plurality of layers ofillumination information, separately shading the first surface based onthe plurality of layers of illumination information corresponding to thefirst surface, the observer position, and the viewing angle, to obtainshading results respectively generated by the plurality of layers ofillumination information corresponding to the first surface underillumination of the light source; obtaining a shading result of thefirst surface in the screen space under illumination of the light sourcebased on the shading results respectively generated by the plurality oflayers of illumination information corresponding to the first surface;or performing accumulation processing on the plurality of layers ofillumination information corresponding to the first surface to obtainaccumulated illumination information corresponding to the first surface;and obtaining a shading result of the first surface in the screen spaceunder illumination of the light source based on the accumulatedillumination information corresponding to the first surface, theobserver position, and the viewing angle.

In the solution shown in this application, if the first surface underillumination of any one light source only corresponds to one layer ofillumination information, the shading device may directly determine ashading result of the first surface based on the layer of illuminationinformation, an observer position, and a viewing angle.

If the first surface under illumination of any one light sourcecorresponds to a plurality of layers of illumination information, theshading device may first determine a shading result of each layer ofillumination information for the first surface, and then accumulate allshading results of the first surface to obtain a shading result of thefirst surface. Alternatively, the shading device may first determine aplurality of layers of illumination information for accumulation, toobtain accumulated illumination information. Then, a shading result ofthe first surface is determined based on the accumulated illuminationinformation. In this way, a shading result of each surface of thethree-dimensional object may be determined based on stored illuminationinformation.

In a possible implementation, each layer of illumination information ofthe plurality of layers of illumination information included in thefirst group of illumination information corresponds to illuminationinformation in different incident ranges or illumination information indifferent reflection ranges; and the performing, in screen space,shading processing on the three-dimensional object based on illuminationinformation corresponding to each surface of the three-dimensionalobject under illumination of a current light source, the observerposition, and the viewing angle includes: for a target position point onthe first surface of the three-dimensional object, separately selecting,from a group of illumination information corresponding to the firstsurface under illumination of each current light source, at least onelayer of illumination information closest to a viewing anglecorresponding to the target position point; and performing shadingprocessing on the target position point in the screen space based on theat least one layer of illumination information selected from each groupof illumination information, the observer position, and the viewingangle corresponding to the target position point.

In the solution shown in this application, for the target position pointon the first surface of the three-dimensional object, before shading isperformed, a group of illumination information corresponding to thefirst surface under illumination of each current light source isobtained. In each group of illumination information, at least one layerof illumination information closest to the viewing angle correspondingto the target position point is selected. The shading device performsshading processing on the target position point by using the at leastone layer of illumination information selected from each group ofillumination information, the observer position, and the viewing anglecorresponding to the target position point. In this way, illuminationinformation can be dynamically selected, and the three-dimensionalobject can be dynamically rendered in real time.

In a possible implementation, the obtaining at least one group ofillumination information corresponding to each surface of athree-dimensional object in target space under illumination of at leastone light source includes: receiving the at least one group ofillumination information that corresponds to each surface of thethree-dimensional object in the target space under illumination of theat least one light source and that is sent by a server; or determiningthe at least one group of illumination information corresponding to eachsurface of the three-dimensional object in the target space underillumination of the at least one light source.

In the solution shown in this application, the shading device mayreceive illumination information from the server, and store theillumination information, or may determine illumination information, andstore the illumination information.

According to a third aspect, this application provides athree-dimensional shading method, where the method is performed by ashading device, and the method includes:

obtaining at least one group of illumination information correspondingto each surface of a three-dimensional object in target space underillumination of at least one light source, where for any surface, afirst group of illumination information corresponding to the surfaceincludes one or more layers of illumination information, and the one ormore layers of illumination information reflect illumination informationof each position point on the surface under illumination of a lightsource to which the first group of illumination information belongs;determining, in the at least one group of illumination information,illumination information corresponding to each surface of thethree-dimensional object under illumination of a current light source;and performing shading processing on the three-dimensional object inscreen space based on the illumination information corresponding to eachsurface of the three-dimensional object under illumination of thecurrent light source and a reflectivity of each surface.

In the solution shown in this application, the shading device may obtainat least one group of illumination information corresponding to eachsurface of each three-dimensional object in target space underillumination of at least one light source. For any surface of thethree-dimensional object, a reflectivity of the surface is obtained. Avalue relationship between the reflectivity of the surface and a presetvalue is determined. If the reflectivity of the surface is less than thepreset value, shading processing is performed on the surface in materialspace based on illumination information corresponding to the surfaceunder illumination of a current light source, to obtain a materialshading result. Then, secondary rendering is performed on the materialshading result of the surface, and shading is performed in screen space.In this way, because illumination information does not need to berecalculated in a shading process, a processing resource of the shadingdevice can be saved.

According to a fourth aspect, this application provides athree-dimensional shading apparatus. The apparatus includes a pluralityof modules, and the plurality of modules implement, by executinginstructions, the three-dimensional shading method provided in the firstaspect.

According to a fifth aspect, this application provides athree-dimensional shading apparatus. The apparatus includes a pluralityof modules, and the plurality of modules implement, by executinginstructions, the three-dimensional shading method provided in thesecond aspect.

According to a sixth aspect, this application provides athree-dimensional shading apparatus. The apparatus includes a pluralityof modules, and the plurality of modules implement, by executinginstructions, the three-dimensional shading method provided in the thirdaspect.

According to a seventh aspect, this application provides athree-dimensional shading computing device. The computing deviceincludes a processor and a memory. The memory stores computerinstructions, and the processor executes the computer instructions toimplement the method in the first aspect and the possibleimplementations of the first aspect.

According to an eighth aspect, this application provides acomputer-readable storage medium. The computer-readable storage mediumstores computer instructions, and when the computer instructions in thecomputer-readable storage medium are executed by a computing device, thecomputing device is enabled to perform the method in the first aspectand the possible implementations of the first aspect, or the computingdevice is enabled to implement a function of the apparatus in the fourthaspect and the possible implementations of the fourth aspect.

According to a ninth aspect, this application provides a computerprogram product including instructions, and when the computer programproduct runs on a computing device, the computing device is enabled toperform the method in the first aspect and the possible implementationsof the first aspect, or the computing device is enabled to implement afunction of the apparatus in the fourth aspect and the possibleimplementations of the fourth aspect.

According to a tenth aspect, this application provides athree-dimensional shading computing device. The computing deviceincludes a processor and a memory. The memory stores computerinstructions, and the processor executes the computer instructions toimplement the method in the second aspect and the possibleimplementations of the second aspect.

According to an eleventh aspect, this application provides acomputer-readable storage medium. The computer-readable storage mediumstores computer instructions, and when the computer instructions in thecomputer-readable storage medium are executed by a computing device, thecomputing device is enabled to perform the method in the second aspectand the possible implementations of the second aspect, or the computingdevice is enabled to implement a function of the apparatus in the fifthaspect and the possible implementations of the fifth aspect.

According to a twelfth aspect, this application provides a computerprogram product including instructions, and when the computer programproduct runs on a computing device, the computing device is enabled toperform the method in the second aspect and the possible implementationsof the second aspect, or the computing device is enabled to implement afunction of the apparatus in the fifth aspect and the possibleimplementations of the fifth aspect.

According to a thirteenth aspect, this application provides athree-dimensional shading computing device. The computing deviceincludes a processor and a memory. The memory stores computerinstructions, and the processor executes the computer instructions toimplement the method in the third aspect and the possibleimplementations of the third aspect.

According to a fourteenth aspect, this application provides acomputer-readable storage medium. The computer-readable storage mediumstores computer instructions, and when the computer instructions in thecomputer-readable storage medium are executed by a computing device, thecomputing device is enabled to perform the method in the third aspectand the possible implementations of the third aspect, or the computingdevice is enabled to implement a function of the apparatus in the sixthaspect and the possible implementations of the sixth aspect.

According to a fifteenth aspect, this application provides a computerprogram product including instructions, and when the computer programproduct runs on a computing device, the computing device is enabled toperform the method in the third aspect and the possible implementationsof the third aspect, or the computing device is enabled to implement afunction of the apparatus in the sixth aspect and the possibleimplementations of the sixth aspect.

According to a sixteenth aspect, this application provides athree-dimensional shading system. The system includes a server and ashading device. The server is configured to implement the method in thefirst aspect and the possible implementations of the first aspect, andthe shading device is configured to implement the method in the secondaspect and the possible implementations of the second aspect.

Beneficial effects brought by the technical solutions provided in thisapplication include at least the following.

In this application, the illumination information in the target space isdetermined and provided for the shading device, and the shading deviceperforms shading processing on the three-dimensional object in thetarget space by using the illumination information. In this way, fortarget space, the server may calculate illumination information once,and provide the illumination information for the device that performsshading processing on the target space. Therefore, the shading devicemay perform shading processing on the target space based on the viewingangle and the observer position that are determined by the shadingdevice and the illumination information provided by the server. Inaddition, even if the shading device obtains that the viewing angleand/or the observer position change/changes, the illuminationinformation does not need to be re-determined. Therefore, the processingresource of the shading device can be saved.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a schematic diagram of a structure of a computing deviceaccording to an example embodiment of this application;

FIG. 2 is a flowchart of a three-dimensional space shading methodaccording to an example embodiment of this application;

FIG. 3 is a schematic diagram of a layer of illumination informationunder illumination of a light source according to an example embodimentof this application;

FIG. 4 is a schematic diagram of a plurality of layers of illuminationinformation under illumination of a light source according to an exampleembodiment of this application;

FIG. 5 is a schematic diagram of a plurality of layers of illuminationinformation under illumination of two light sources according to anexample embodiment of this application;

FIG. 6 is a schematic diagram of light bounce according to an exampleembodiment of this application;

FIG. 7 is a schematic diagram of light reflection according to anexample embodiment of this application;

FIG. 8 is a schematic diagram of illumination information of N incidentranges under a light source according to an example embodiment of thisapplication;

FIG. 9 is a schematic diagram of illumination information of N incidentranges under a light source according to an example embodiment of thisapplication;

FIG. 10 is a flowchart of a three-dimensional space shading methodaccording to an example embodiment of this application;

FIG. 11 is a schematic diagram of displaying three-dimensional space bya terminal device according to an example embodiment of thisapplication;

FIG. 12 is a schematic diagram of three-dimensional space renderingaccording to an example embodiment of this application;

FIG. 13 is a schematic diagram of a structure of a three-dimensionalspace shading apparatus according to an example embodiment of thisapplication; and

FIG. 14 is a schematic diagram of a structure of a three-dimensionalspace shading apparatus according to an example embodiment of thisapplication.

DESCRIPTION OF EMBODIMENTS

To make objectives, technical solutions, and advantages of thisapplication clearer, the following further describes implementations ofthis application in detail with reference to the accompanying drawings.

For ease of understanding of embodiments of this application, thefollowing first describes concepts of terms used.

1. A three-dimensional model (Three Dimensional Model, 3D Model) is arepresentation of identifiers of polygons and texture mappings of anobject, and is usually displayed by using a terminal device.

2. Geometry (Geometry) is a polygon element such as a point, a line, atriangle, and a polygon in a three-dimensional model.

3. A texture (Texture) may also be referred to as a texture mapping, atexture map, or the like, for example, a rough texture mapping, a smoothtexture mapping, and a wood texture mapping. In computer graphics, abitmap stored in a memory is wrapped on a surface of a three-dimensionalobject.

4. Render (Render) is a process of generating an image by using athree-dimensional model.

5. Shading (Shading) is to shade an object in a rendering process, thatis, calculate a pixel value of each pixel in an image based on adirection of the object relative to light and a distance between theobject and a light source, where the pixel value determines graphicsdisplayed in the final image and brightness effects.

6. Ray tracing (Ray Tracing) is a special rendering method that trackslight emitted from an eye rather than light from a light source inthree-dimensional computer graphics.

In an existing method for shading a three-dimensional object, a lightray collides with a three-dimensional object in three-dimensional space,and then shading processing is performed in screen space. If an observerposition and a viewing angle of an observer change, shading processingneeds to be recalculated in an entire rendering process, and acalculation amount is large. Therefore, a three-dimensional shadingmethod with a small calculation amount is required.

The three-dimensional shading method in this embodiment of thisapplication may be applied to a plurality of rendering scenarios, forexample, a three-dimensional game rendering scenario, and a movieanimation production scenario. The three-dimensional game renderingscenario may be a multi-user game sharing scenario. In addition, after ashading result of the three-dimensional object is obtained by using themethod, terminals such as a mobile phone, a tablet computer, andaugmented reality (Augmented Reality, AR) or virtual reality (VirtualReality, VR) glasses may display the three-dimensional object based onthe shading result.

The three-dimensional shading method provided in this embodiment of thisapplication may be applied to shading processing on a three-dimensionalobject in three-dimensional space. The three-dimensional shading methodmay be executed by a three-dimensional shading apparatus (hereinafterreferred to as a shading apparatus for short). The shading apparatus maybe a hardware apparatus, for example, a computing device of a servertype or a terminal type, or may be a software apparatus (for example,may be a set of software programs running on the hardware apparatus). Inaddition, the shading apparatus may alternatively be a virtual shadingdevice. For example, the shading apparatus is a cloud mobile phone. Inthis embodiment of this application, an example in which the shadingapparatus is a terminal device is used for description.

When the rendering apparatus is a hardware apparatus, an embodiment ofthis application further provides a three-dimensional shading computingdevice. FIG. 1 is an example of a possible architecture diagram of acomputing device 100.

The computing device 100 includes a memory 101, a processor 102, acommunications interface 103, and a bus 104. The memory 101, theprocessor 102, and the communications interface 103 implement mutualcommunication connections through the bus 104.

The memory 101 may be a read only memory (Read Only Memory, ROM), astatic storage device, a dynamic storage device, or a random accessmemory (Random Access Memory, RAM). The memory 101 may store a program.When the program stored in the memory 101 is executed by the processor102, the processor 102 and the communications interface 103 areconfigured to perform a three-dimensional shading method. The memory 101may further store a data set. For example, the memory 101 is configuredto store one or more layers of illumination information.

The processor 102 may be a general-purpose central processing unit(Central Processing Unit, CPU), a graphics processing unit (graphicsprocessing unit, GPU), or the like.

The communications interface 103 uses a transceiver module, for example,but not limited to a transceiver, to implement communication between thecomputing device 100 and another device or a communications network. Forexample, the data set may be obtained by using the communicationsinterface 103.

The bus 104 may include a path for transmitting information betweencomponents (for example, the memory 101, the processor 102, and thecommunications interface 103) of the computing device 100.

The following describes, with reference to FIG. 2 , a three-dimensionalshading method provided in an embodiment of this application. The methodmay be performed by a server. As shown in FIG. 2 , a processingprocedure of the method is as follows:

Step 201: The server obtains position information and an intensity of atleast one light source in target space.

The target space is any three-dimensional space to be displayed. In agame scenario, the target space is any scene image or the like. A lightsource is a light source in the target space. The light source may beany one of a directional light source, a point light source, a linearlight source, a surface light source, or a body light source. Lightemitted by the light source is light of a preset color. The directionallight source simulates light emitted from an infinitely distant source.In this embodiment of this application, an example in which the lightsource in the target space is the point light source is used fordescription. In this embodiment of this application, there may be one ormore light sources in one target space. For example, in a scenario, astime changes, scenario content does not change, but a quantity of lightsources in the scenario changes. In another scenario, an operation of auser changes a quantity of light sources. In another scenario, there isalways one light source, but a position of the light source changes astime changes, and it is also considered that the target scenarioincludes a plurality of light sources. For example, in a scenario, thesun rises and falls in a day, and the sunlight is a light source whoseposition changes. A more accurate dynamic change can be finallypresented to a user by changing a quantity of light sources or aposition of the light source. The light source in this embodiment ofthis application may be a white light source.

In this embodiment, when drawing the target space, a person skilled inthe art sets position information and an intensity of at least one lightsource. The position information of the light source is used to indicatea position of the light source in the target space. The intensity of thelight source may be represented by using a color of the light source, ormay be represented by using A watts per square meter, where A is a valueof the intensity of the light source.

When determining illumination information in the target space, theserver may obtain the stored position information and intensity of theat least one light source in the target space.

Step 202: The server determines, based on the position information andthe intensity of the at least one light source, at least one group ofillumination information corresponding to each surface of athree-dimensional object in the target space under illumination of theat least one light source, where for any surface, a first group ofillumination information corresponding to the surface includes one ormore layers of illumination information, and the one or more layers ofillumination information reflect illumination information of eachposition point on the surface under illumination of a light source towhich the first group of illumination information belongs.

Each three-dimensional object includes a point, a line, a triangle, apolygon, and the like. For example, a cube three-dimensional objectincludes six quadrilaterals, or includes 12 triangles, and a cylindricalthree-dimensional object includes a plurality of triangles. Eachthree-dimensional object may include a plurality of surfaces. Forexample, the cube three-dimensional object includes six square surfaces,and the cylindrical three-dimensional object includes two circularsurfaces and a plurality of triangular surfaces, that is, a side surfaceof the cylindrical three-dimensional object includes a plurality oftriangles. For any surface, the first group of illumination informationcorresponding to the surface includes the one or more layers ofillumination information, and the one or more layers of illuminationinformation reflect the illumination information of each position pointon the surface under illumination of the light source to which the firstgroup of illumination information belongs. The first group ofillumination information herein indicates any group of illuminationinformation corresponding to the surface, but does not indicate aspecific group of illumination information. Each position point on thesurface may also be referred to as each pixel on the surface.

In this embodiment, after obtaining the position information and lightray information of the at least one light source, the server maydetermine, for each light source based on the intensity of the lightsource, the position information of the light source, and positioninformation of each three-dimensional object in the target space, agroup of illumination information corresponding to each surface of eachthree-dimensional object in the target space under illumination of thelight source, that is, obtain a group of illumination informationcorresponding to each surface of the three-dimensional object in thetarget space under illumination of the light source. The group ofillumination information includes one or more layers of illuminationinformation. For example, in FIG. 3 , the at least one light source isone light source, the three-dimensional object is a cube, and a firstsurface of the cube corresponds to one layer of illuminationinformation. In FIG. 4 , the at least one light source is one lightsource, the three-dimensional object is a cube, and a second surface ofthe cube corresponds to a plurality of layers of illuminationinformation. In FIG. 5 , the at least one light source is two lightsources: a light source 1 and a light source 2, and thethree-dimensional object is a cube. On a second surface of the cube,under illumination of the light source 1, the second surface correspondsto a group of illumination information, and under illumination of thelight source 2, the second surface corresponds to a group ofillumination information. The two groups of illumination informationeach include a plurality of layers of illumination information. In thisway, under illumination of any one light source, each surface of thethree-dimensional object in the target space corresponds to a group ofillumination information.

Herein, in a casting algorithm for ray tracing, under illumination of alight source, for a surface of the three-dimensional object, when thesurface corresponds to one layer of illumination information, thesurface is directly illuminated by the light source only once, or isilluminated by bounce only once; when the surface corresponds to aplurality of layers of illumination information, the surface is directlyilluminated by the light source once and is illuminated by bounce onceor for a plurality of times, or is not directly illuminated by the lightsource, but is illuminated by bounce for a plurality of times.“Illuminated by bounce” herein means that a light ray does not directlyilluminate the three-dimensional object from a light source, butilluminates the three-dimensional object by reflection of anotherthree-dimensional object. For example, as shown in FIG. 6 , the lightray of the light source illuminates a three-dimensional object A, thethree-dimensional object A reflects the light ray to a three-dimensionalobject B, and the light ray illuminates the three-dimensional object B.That is, the light ray illuminates the three-dimensional object B, thatis, illuminates the three-dimensional object B by bounce.

Optionally, under illumination of a light source, if a surface of thethree-dimensional object corresponds to one layer of illuminationinformation, the layer of illumination information may also be one layerof illumination information obtained after a plurality of layers ofillumination information corresponding to the surface are superposed.

Step 203: The server provides the at least one group of illuminationinformation for a device that performs shading processing on the targetspace.

In different scenarios, devices that perform shading processing on thetarget space are different. Specifically, in a game sharing scenario,devices that perform shading processing on the target space are terminaldevices used by a plurality of users currently playing the game. In amovie animation scenario, devices that perform shading processing on thetarget space are terminal devices used by a plurality of users currentlywatching a movie animation, cloud mobile phones used by a plurality ofusers currently watching the movie animation, or the like.

In this embodiment, the server may determine devices that performshading processing on the target space, that is, shading devices, andsend the at least one group of illumination information in the targetspace to these devices. For example, in a game sharing scenario, theserver may determine that a plurality of terminal devices that log in toa shared game are terminal devices shading the target space, and theserver may send illumination information to these terminal devices. Inthis way, for target space, the server may calculate illuminationinformation once, and send the illumination information to the devicethat performs shading processing on the target space. Therefore, theshading device may perform shading processing on the target space basedon a viewing angle and an observer position determined by the shadingdevice and the illumination information provided by the server. In thisway, even if the shading device learns that the viewing angle and/or theobserver position change, the illumination information does not need tobe re-determined, to save a processing resource of the shading device.

It should be noted herein that, when the shading apparatus is a virtualshading device, after completing shading processing on the target space,the virtual shading device sends a shading result of the target space toa terminal device that displays the target space for display.

In addition, the server may further send other information of eachthree-dimensional object in the target space to the device that performsshading processing on the target space, where the other information isinformation used during the shading processing. For example, the otherinformation is material information (the material information includes atexture) of each surface of each three-dimensional object, positioninformation of each three-dimensional object, and geometric informationof each three-dimensional object. The material information may includean albedo (Albedo), a metallic (Metallic), a roughness (Roughness), areflectivity (Reflectance), and the like of each position point on thesurface, a normal (Normal, N), an ambient occlusion (Ambient Occlusion,AO) layer, and the like of the surface. The AO layer may be referred toas a shadow layer. When two three-dimensional objects are close to eachother, a shadow layer is generated. The geometric information is used toindicate geometry forming the three-dimensional object.

Optionally, the at least one group of illumination information mentionedabove may be included in the material information, the server providesthe at least one group of illumination information along with thematerial information for the device that performs shading processing onthe target space.

It should be noted that A and/or B described in this embodiment of thisapplication include three cases: A, B, and A and B.

The following describes detailed processing of each step in theprocedure in FIG. 2 .

In a possible implementation, processing in step 202 may be:

The server obtains light ray information of a light source, where thelight ray information includes a quantity of light rays and a lightdirection. The server determines scattering information of each surfaceof the three-dimensional object in the target space with a light ray ofthe at least one light source based on the intensity, the positioninformation, and the light ray information of the at least one lightsource; and determines, based on the scattering information of eachsurface of the three-dimensional object, the at least one group ofillumination information corresponding to each surface of thethree-dimensional object under illumination of the at least one lightsource.

For a first surface of the three-dimensional object under illuminationof any one light source, the first surface is any surface, andscattering information of the first surface includes an intensity, adirection, and a number of bounces of an incident light ray at eachposition point on the first surface, or includes an intensity, adirection, and a number of bounces of a reflection light ray at eachposition point on the first surface.

In this embodiment, when drawing the target space, a person skilled inthe art sets light ray information of the at least one light source. Thelight ray information of the light source may include a quantity oflight rays, a light intensity, and a light direction of the lightsource, and the quantity of light rays is a quantity of light raysemitted by the light source, for example, 500 light rays. The lightintensity is an intensity of the light ray emitted from the lightsource. The light direction is an angle at which each light ray isemitted from the light source. The server may obtain stored light rayinformation. The server determines a group of illumination informationcorresponding to each surface of the three-dimensional object underillumination of each light source. Specifically, for any one lightsource, the server may determine scattering information of each surfaceof each three-dimensional object in the target space with a light ray ofthe light source based on the position information of the light source,the light ray information of the light source, and the positioninformation of the three-dimensional object in the space. The scatteringinformation may be determined in the following manner:

A process in which the server determines the scattering information byusing a ray casting algorithm in ray tracing is as follows: For anysurface of the three-dimensional object, the server determines, based onthe position information of the three-dimensional object, the lightintensity, the position information, and the light direction of thelight source, an intensity, a direction, and a source of an incidentlight ray cast to each position point on the surface. The intensity, thedirection, and the source of the incident light ray at each positionpoint on the surface are scattering information corresponding to thesurface. The source of the incident light ray records a number ofbounces when the incident light ray is bounced on the surface afterbeing emitted from the light source. For example, the light ray directlycomes from the light source, and a number of bounces is 0. For anotherexample, the light ray does not directly come from the light source, andwhen incident to a first surface of a three-dimensional object, thelight ray passes a surface A of a first three-dimensional object and asurface B of a second three-dimensional object, that is, a number ofbounces is 2. For a three-dimensional object, that the light raydirectly comes from the light source means that the light ray emitted bythe light source directly illuminates the surface of thethree-dimensional object, and that the light ray does not directly comefrom the light source means that the light ray emitted by the lightsource illuminates the surface of the three-dimensional object onlyafter reflection and/or diffuse reflection of another three-dimensionalobject.

Alternatively, for any surface of the three-dimensional object, theserver determines, based on the position information of thethree-dimensional object, the light intensity, the position information,and the light direction of the light source, an intensity, a direction,and a source of a reflection light ray cast to each position point onthe surface. The intensity, the direction, and the source of thereflection light ray at each position point on the surface arescattering information corresponding to the surface. The source of thereflection light ray records a number of bounces when the reflectionlight ray bounces on the surface after being emitted from the lightsource. For example, the light ray directly comes from the light source,and a number of bounces is 0. For another example, the light ray doesnot directly come from the light source, and when reflected from a firstsurface of a three-dimensional object, the light ray passes a surface Aof a first three-dimensional object and a surface B of a secondthree-dimensional object, that is, a number of bounces is 2. For athree-dimensional object, that the light ray directly comes from thelight source means that the light ray emitted by the light sourcedirectly illuminates the surface of the three-dimensional object to forma reflection light ray, and that the light ray does not directly comefrom the light source means that the light ray emitted by the lightsource illuminates the surface of the three-dimensional object to formthe reflection light ray only after reflection and/or diffuse reflectionof another three-dimensional object. FIG. 7 provides a schematic diagramin which a first surface of the three-dimensional object reflects areceived light ray emitted by a light source.

Then, the server may determine, by using the scattering information ofeach surface of each three-dimensional object, at least one group ofillumination information corresponding to each surface of eachthree-dimensional object under illumination of the at least one lightsource.

It should be noted herein that a manner of determining an intensity of alight ray incident to any surface is as follows: The server may obtain adirection of a light ray reflected from a light source, transmission ofthe light ray is straight-line transmission, and the server may furtherobtain position information of each three-dimensional object. Inaddition, a direction of the light ray after reflection and diffusereflection may be determined based on a texture mapping of a surface ofthe three-dimensional object. In this way, a position and a direction ofthe light ray cast to the three-dimensional object may be determined.

It should be noted herein that a manner of determining an intensity of alight ray incident to any surface is as follows: The intensity of eachlight ray emitted from the light source is recorded in the intensity ofthe light source. The light ray of the light source has a presetintensity when emitted from the light source. A transmission distance ofthe light ray emitted from the light source and incident to the surfacemay be calculated. The transmission distance is multiplied by a presetattenuation value to obtain a product, and the product is subtractedfrom the preset intensity of the light ray to obtain the intensity ofthe incident light ray. Alternatively, the light ray of the light sourcehas a preset intensity when emitted from the light source. A totalattenuation amount when the light ray passes all three-dimensionalobjects may be calculated based on a texture mapping of thethree-dimensional object, and the intensity of the incident light ray isobtained by subtracting the total attenuation amount from the presetintensity. Alternatively, the intensity of the incident light ray may bedetermined by using the two manners. A manner of determining anintensity of a light ray reflected from any surface is the same as amanner of determining an intensity of an incident light ray incident toany surface, and details are not described herein again. Herein, theintensity of each light ray may be represented by a color of the lightsource, or may be represented by A watts per square meter, where A is avalue of the intensity of the light ray.

In a possible implementation, processing of the server determining atleast one group of illumination information corresponding to eachsurface of each three-dimensional object under illumination of at leastone light source based on the scattering information of each surface ofeach three-dimensional object is:

for a first surface of the three-dimensional object in the target space,separately superposing intensities and directions of light rays thathave a same number of bounces and that are in scattering informationcorresponding to the first surface under illumination of a target lightsource in the at least one light source, to obtain a superpositionintensity and superposition direction of a light ray that has eachnumber of bounces and that corresponds to the first surface; anddetermining, based on the superposition intensity and superpositiondirection of the light ray that has each number of bounces, a group ofillumination information corresponding to the first surface underillumination of the target light source.

The three-dimensional object is any three-dimensional object in thetarget space, the first surface is any surface of the three-dimensionalobject, and the target light source is any one light source in the atleast one light source in the target space.

In this embodiment, under illumination of the target light source, thescattering information corresponding to the first surface includes adirection and a source of an incident light ray of each position pointon the first surface. The server may superpose directions of incidentlight rays having a same number of bounces at each position point on thefirst surface, to obtain a direction of the incident light ray at eachposition point, and superpose intensities of the incident light rayshaving the same number of bounces at each position point, to obtain asuperposition intensity of the incident light ray at each positionpoint. For the first surface, the server determines the superpositionintensity and the superposition direction of the incident light rayhaving each number of bounces as a group of illumination information ofthe first surface under illumination of the target light source. In thegroup of illumination information, each layer of illuminationinformation is the superposition intensity and the superpositiondirection of the incident light ray having each number of bounces.

Alternatively, under illumination of the target light source, thescattering information corresponding to the first surface includes adirection and a source of a reflection light ray at each position pointon the first surface. The server may superpose directions of reflectionlight rays having a same number of bounces at each position point on thefirst surface, to obtain a superposition direction of the reflectionlight ray at each position point, and superpose intensities of thereflection light rays having the same number of bounces at each positionpoint, to obtain a superposition intensity of the reflection light rayat each position point. For the first surface, the server determines thesuperposition intensity and the superposition direction of thereflection light ray having each number of bounces as a group ofillumination information of the first surface under illumination of thetarget light source. In the group of illumination information, eachlayer of illumination information is the superposition intensity and thesuperposition direction of the reflection light ray having each numberof bounces.

Herein, under illumination of a light source, if the scatteringinformation corresponding to the first surface includes one number ofbounces, it indicates that the first surface corresponds to one layer ofillumination information; or if the scattering information correspondingto the first surface includes a plurality of numbers of bounces, itindicates that the first surface corresponds to a plurality of layers ofillumination information.

Based on the foregoing description, it can be learned that, underillumination of each light source, when illumination information isdetermined by using a casting algorithm in ray tracing, an intensity anda direction of a light ray in the scattering information correspondingto the first surface under illumination of the target light source arean incident intensity and an incident direction of a light ray incidentto the first surface, or an intensity and a direction of a light ray inthe scattering information corresponding to the first surface underillumination of the target light source are a reflection intensity and areflection direction of a light ray reflected from the first surface.

In addition, based on the foregoing description, it can be learned that,when a ray casting algorithm in ray tracing is used, determinedillumination layer information is illumination information obtained bydirect illumination of the light source and illumination informationobtained by illumination by bounce.

It should be noted that, in this embodiment of this application, atransmission speed of a light ray in three-dimensional space isinfinite. Therefore, it may be considered that light rays having a samenumber of bounces are incident to a same position point on a surface ata same time point, that is, may be directly superposed. The foregoing “asame number of bounces” means that a light ray incident to or reflectedfrom a position point on a surface has a same quantity of reflectionand/or diffuse reflection times. For example, if a light ray A isemitted from a light source and is directly cast to a surface positionpoint 1, and a light ray B is emitted from a light source and isdirectly cast to the surface position point 1, a number of bounces ofthe light ray A is the same as that of the light ray B. For anotherexample, a light ray A is emitted from a light source, is incident to afirst three-dimensional object, and arrives at a surface position point1 after one reflection of the first three-dimensional object. A lightray B is emitted from a light source, is incident to a secondthree-dimensional object, and arrives at a surface position point 1after one reflection of the second three-dimensional object. Both thelight ray A and the light ray B arrive at the surface position point 1after one bounce, and therefore, there is a same number of bounces.

It should be further noted herein that, although the more real light rayis obtained when determining the illumination information, the morelikely a real three-dimensional object is displayed for the user.However, to save a calculation amount, because human eyes may not senseimpact of a light ray bounced for a plurality of times on a displayedthree-dimensional object, a maximum number of bounces may be set. Forexample, the maximum number of bounces is 2, that is, the light sourcedirectly illuminates once and is bounced twice.

In a possible implementation, each light source is divided into aplurality of incident ranges based on an incident angle, and a quantityof incident ranges may be set based on an actual requirement. Forexample, the plurality of incident ranges are four incident ranges, afirst incident range is 0 degree to 45 degrees, including 0 degree; asecond incident range is 45 degrees to 90 degrees, including 90 degrees;a third incident range is 90 degrees to 135 degrees, including 135degrees; and a fourth incident range is 135 degrees to 180 degrees,including 180 degrees. In this case, scattering information includes anincident intensity and an incident direction of a light ray, thethree-dimensional object under illumination of each light sourcecorresponds to one group of illumination information, and each group ofillumination information includes one or more layers of illuminationinformation. Specifically, processing for obtaining each group ofillumination information is as follows:

For a target position point on a first surface of the three-dimensionalobject, the target position point is any position point on the firstsurface. The server stores an incident range, and determines, inscattering information corresponding to the first surface underillumination of the target light source and based on an incident anglein the incident range, an intensity and a direction of a light ray thatbelongs to each incident range and that is in light rays incident to thetarget position point. For example, an incident range is 0 to 45degrees, and a light ray whose incident angle is 30 degrees belongs tothe incident range.

For a first incident range in the incident ranges, the server superposesintensities of light rays that belong to the first incident range toobtain a superposition intensity of a light ray at the target positionpoint, and superposes directions of the light rays that belong to thefirst incident range to obtain a superposition direction of the lightray at the target position point. In this manner, the server obtains thesuperposition intensity and the superposition direction of the light rayat each position point on the first surface in each incident range. Inthis way, it is equivalent to that a group of illumination informationunder illumination of each light source is obtained for the firstsurface, each group of illumination information includes a plurality oflayers of illumination information, and each layer of illuminationinformation is illumination information of one incident range. Forexample, FIG. 8 shows illumination information of N incident rangesunder one light source. In FIG. 8 , the three-dimensional object is acube, a first surface is a surface of the three-dimensional object, andan incident range is N incident ranges, that is, an incident range 0 toan incident range N−1.

Alternatively, for a first incident range in the incident ranges, theserver determines an intensity and a direction of a ray of each numberof bounces in light rays belonging to the first incident range. Theserver separately superposes intensities of light rays that have eachnumber of bounces and that belong to the first incident range, to obtaina superposition intensity of a light ray at a target position point foreach number of bounces, and separately superposes directions of lightrays that have each number of bounces and that belong to the firstincident range, to obtain a superposition direction of the light ray atthe target position point for each number of bounces. In this manner,the server obtains, in each incident range, the superposition intensityand the superposition direction of the light ray at each position pointon the first surface for each number of bounces. In this way, it isequivalent to that a group of illumination information underillumination of each light source is obtained for the first surface,each group of illumination information includes a plurality of layers ofillumination information, and each layer of illumination information isillumination information with a same number of bounces and incidentrange. For example, FIG. 9 shows illumination information of N incidentranges under one light source. In FIG. 9 , a three-dimensional object isa cube, a first surface is a surface of the three-dimensional object,and an incident range is N incident ranges, that is, an incident range 0to an incident range N−1, and each incident range corresponds to twonumbers of bounces. In this way, a group of illumination information ofthe first surface under illumination of each light source includes N*2layers of illumination information.

In a possible implementation, each light source is divided into aplurality of reflection ranges based on a reflection angle, and aquantity of reflection ranges may be set based on an actual requirement.For example, the plurality of reflection ranges are four reflectionranges, a first reflection range is 0 degree to 45 degrees, including 0degree; a second reflection range is 45 degrees to 90 degrees, including90 degrees; a third reflection range is 90 degrees to 135 degrees,including 135 degrees; and a fourth reflection range is 135 degrees to180 degrees, including 180 degrees. In this case, scattering informationincludes a reflection intensity and a reflection direction of a lightray, the three-dimensional object under illumination of each lightsource corresponds to one group of illumination information, and eachgroup of illumination information includes one or more layers ofillumination information. Specifically, processing for obtaining eachgroup of illumination information is as follows:

For a target position point on a first surface of the three-dimensionalobject, the target position point is any position point on the firstsurface. The server stores a reflection range, and determines, inscattering information corresponding to the first surface underillumination of the target light source and based on a reflection anglein the reflection range, an intensity and a direction of a light raythat belongs to each reflection range and that is in light raysreflected from the target position point.

For a first reflection range in the reflection ranges, the serversuperposes intensities of light rays that belong to the first reflectionrange to obtain a superposition intensity of a light ray at the targetposition point, and superposes directions of the light rays that belongto the first reflection range to obtain a superposition direction of thelight ray at the target position point. In this manner, the serverobtains the superposition intensity and the superposition direction ofthe light ray at each position point on the first surface in eachreflection range. In this way, it is equivalent to that a group ofillumination information under illumination of each light source isobtained for the first surface, each group of illumination informationincludes a plurality of layers of illumination information, and eachlayer of illumination information is illumination information of onereflection range.

Alternatively, for a first reflection range in the reflection ranges,the server determines an intensity and a direction of a ray of eachnumber of bounces in light rays belonging to the first reflection range.The server separately superposes intensities of light rays that haveeach number of bounces and that belong to the first reflection range, toobtain a superposition intensity of a light ray at a target positionpoint for each number of bounces, and separately superposes directionsof the light rays that have each number of bounces and that belong tothe first reflection range, to obtain a superposition direction of thelight ray at the target position point for each number of bounces. Inthis manner, the server obtains, in each reflection range, thesuperposition intensity and the superposition direction of the light rayat each position point on the first surface for each number of bounces.In this way, it is equivalent to that a group of illuminationinformation under illumination of each light source is obtained for thefirst surface, each group of illumination information includes aplurality of layers of illumination information, and each layer ofillumination information is illumination information with a same numberof bounces and reflection range.

Specifically, intensity superposition and direction superposition of alight ray are described above, and details are not described hereinagain.

In addition, in a possible implementation, in step 202 in thisembodiment of this application, a layer of illumination informationcorresponding to each surface of each three-dimensional object in thetarget space may be further determined through Phong lighting (the Phonglighting may be processing in a world coordinate system), and theprocessing is as follows:

Under illumination of one light source, the server may obtain, by usingthe Phong lighting, a layer of illumination information corresponding toeach surface, that is, a group of illumination information correspondingto each surface includes the layer of illumination information. Thelayer of illumination information includes an illumination intensity andan illumination direction of each surface of the three-dimensionalobject. Specifically, the illumination intensity of each position pointon each surface is an intensity of the light source. In a worldcoordinate system, the position information of the light source is acoordinate of the light source. The server may obtain the coordinate ofthe light source and a coordinate of each position point on eachsurface, and subtract the coordinate of each position point from thecoordinate of the light source to obtain a vector of the light sourcepointing to the position point. A direction of the vector correspondingto each position point is an illumination direction of each positionpoint. Therefore, the layer of illumination information corresponding toeach surface includes the illumination intensity and the illuminationdirection of each position point on the surface.

It should be noted herein that, in the Phong lighting, an intensity ofthe light source uses a color of the light source. For example, anintensity of a light source whose red, green, and blue (Red, Green,Blue, RGB) is (255, 255, 255) is greater than that of a light sourcewhose RGB is (128, 128, 128).

In this embodiment of this application, as shown in FIG. 10 , aprocedure in which a terminal device performs three-dimensional shadingin screen space is further provided:

Step 1001: The terminal device obtains at least one group ofillumination information corresponding to each surface of athree-dimensional object in target space under illumination of at leastone light source, where for any surface, a first group of illuminationinformation corresponding to the surface includes one or more layers ofillumination information, and the one or more layers of illuminationinformation reflect illumination information of each position point onthe surface under illumination of a light source to which the firstgroup of illumination information belongs.

The terminal device is a device that performs shading processing on thetarget space, for example, a mobile phone, a tablet, or the like.

In this embodiment, the terminal device may receive the at least onegroup of illumination information that corresponds to each surface ofeach three-dimensional object in the target space under illumination ofthe at least one light source and that is sent by a server, and thenstore the at least one group of illumination information; or theterminal device determines the at least one group of illuminationinformation corresponding to each surface of each three-dimensionalobject in the target space under illumination of the at least one lightsource, and stores the at least one group of illumination information. Adetermining process is the same as the foregoing process in which theserver determines the at least one group of illumination information,and details are not described herein again.

It should be noted herein that a scenario in which the server providesthe illumination information may be a scenario in which a plurality ofterminal devices perform online sharing, or may be an offline scenario.In a scenario in which the terminal device provides the illuminationinformation, because computing power of the terminal device is generallysmall, the scenario may be a scenario in which the illuminationinformation is stored offline. Certainly, in the case that the computingpower of the terminal device is large enough, processing of determiningthe illumination information in the online scenario may also beimplemented.

Step 1002: The terminal device obtains an observer position and aviewing angle of an observer.

In this embodiment, in different scenarios, the terminal device obtainsthe observer position of the observer in different manners. For example,in a game scenario, an initial position is preset. An observer (that is,a game player) controls a player by using a game lever to move in targetspace. The terminal device determines movement information of a currentgame lever relative to the initial position, and determines a positionof a current player, that is, obtains the observer position of theobserver. The observer position is a position of the observer in a worldcoordinate system.

The terminal device may detect a line-of-sight direction of eyes, toobtain the viewing angle of the observer.

Step 1003: The terminal device performs, in the screen space, shadingprocessing on the three-dimensional object in the target space based onillumination information corresponding to each surface of thethree-dimensional object in the target space under illumination of acurrent light source, the observer position, and the viewing angle.

In this embodiment, the terminal device may create a view matrix (ViewMatrix) based on a position coordinate of the observer position and theviewing angle of the observer. Specifically, the terminal device definesthree mutually perpendicular axes (x-axis, y-axis, and z-axis) using theobserver as a coordinate origin, defines observation space of theobserver by using the three mutually perpendicular axes, and constructsthe view matrix by using the three axes and a translation vector. Theview matrix may be represented as follows:

$\begin{bmatrix}{Rx} & {Ry} & {Rz} & 0 \\{Ux} & {Uy} & {Uz} & 0 \\{Dx} & {Dy} & {Dz} & 0 \\0 & 0 & 0 & 1\end{bmatrix}_{*}\begin{bmatrix}1 & 0 & 0 & {- {Px}} \\0 & 1 & 0 & {- {Py}} \\0 & 0 & 1 & {- {Pz}} \\0 & 0 & 0 & 1\end{bmatrix}$

In the view matrix, (Dx, Dy, Dz) is a vector in a z direction, and isobtained by subtracting a coordinate origin of the world coordinatesystem from a position coordinate of the observer in the worldcoordinate system, that is, a vector in a direction of the viewingangle. (Rx, Ry, Rz) is a vector in an x direction, and is obtained bymultiplying the vector in the z direction by a predefined upper vector(0, 1, 0). (Ux, Uy, Uz) is a vector in a y direction, and is obtained bymultiplying the vector in the z direction by the vector in the xdirection. (Px, Py, Pz) is a vector of the observer position.

By using the view matrix, the world coordinate of each three-dimensionalobject in the target space is transformed into a coordinate relative tothe observer position and direction, that is, the position coordinate ofeach three-dimensional object in an observer coordinate system isobtained.

The terminal device determines a current light source in the targetspace based on a current display progress of the target space. Forexample, the server provides the terminal device with a correspondence(set by a producer of the target space) between display time and a lightsource of the target space, and the terminal device may determine thecurrent light source of the target space based on the correspondence; orthe terminal device determines the current light source of the targetspace based on an operation of a user. For example, when detecting anoperation of enabling or disabling a light source by the user, theterminal device determines a change of a light source of the targetspace, and may further determine the light source of the target space.Alternatively, the terminal device determines the current light sourceof the target space based on a display scenario. For example, the serverprovides the terminal device with a correspondence (set by a producer ofthe target space) between a display scenario and a light source of thetarget space, and the terminal device may determine the current lightsource of the target space based on the correspondence.

The terminal device may perform shading processing on thethree-dimensional object in the target space based on illuminationinformation and material information of each surface of eachthree-dimensional object under illumination of the current light source,position information of each three-dimensional object, geometricinformation of each three-dimensional object, and the positioncoordinate of each three-dimensional object in the observer coordinatesystem, to obtain a total shading result of each surface of thethree-dimensional object, where the total shading result is a pixelvalue of each position point when the surface is displayed. If theterminal device is a device for displaying the target space, theterminal device may display each three-dimensional object in the targetspace on a screen by using the total shading result. For example, asshown in FIG. 11 , two terminal devices need to display the targetspace, and an observer position and a viewing angle are different.

In this way, because illumination information of each three-dimensionalobject in the target space can be obtained, even if the observerposition and the viewing angle change, the terminal device may directlyre-perform shading processing on the target space based on theillumination information in the target space, and the illuminationinformation does not need to be recalculated in a shading process.Therefore, a processing resource of the terminal device can be saved.

Herein, an example in which the terminal device performs shadingprocessing on the target space and the terminal device performsdisplaying is used for description. When a virtual shading deviceperforms shading, the virtual shading device performs shading processingon each three-dimensional object in the target space, and then sends ashading result to the terminal device that displays the target space.The terminal device displays the target space based on the shadingresult.

In addition, in this embodiment of this application, in an onlinescenario in which the terminal device provides the illuminationinformation, the terminal device may store the illumination informationin the target space. After the observer position and the viewing angleof the observer change, the stored illumination information may bedirectly used for performing shading processing without recalculatingthe illumination information. Therefore, a processing resource of theterminal device can also be saved.

In step 1003, a processing process in which the terminal device performsshading on each three-dimensional object in the target space isdescribed as follows:

If there are a plurality of the current light sources, underillumination of any one light source of the current light sources,shading processing is separately performed on the three-dimensionalobject in the target space based on illumination informationcorresponding to each surface of the three-dimensional object in thetarget space under illumination of the light source, the observerposition, and the viewing angle, to obtain a shading result of eachsurface of the three-dimensional object in the target space in thescreen space under illumination of the light source; and shading resultsof each surface of the three-dimensional object in the target space inthe screen space under illumination of the current light sources areaccumulated, to obtain a total shading result of each surface of thethree-dimensional object in the target space in the screen space.

In this embodiment, when there are a plurality of the current lightsources in the target space, for a three-dimensional object, underillumination of any one light source of the current light sources, theterminal device may separately perform shading processing on eachsurface of the three-dimensional object by using the illuminationinformation corresponding to each surface of the three-dimensionalobject under illumination of the light source, the observer position,and the viewing angle, to obtain the shading result of each surface ofthe three-dimensional object in the screen space under illumination ofthe light source.

For a surface of the three-dimensional object, the terminal device mayadd shading results of each position point on the surface underillumination of the current light sources, to obtain a total shadingresult of each position point on the surface in the screen space.

In a possible implementation, processing of the terminal deviceobtaining the shading result of each surface of the three-dimensionalobject in the target space under illumination of each light source is asfollows:

Under illumination of any one light source of the current light sources,if a first surface of the three-dimensional object in the target spacecorresponds to one layer of illumination information, a shading resultof the first surface in the screen space under illumination of the lightsource is obtained based on the layer of illumination informationcorresponding to the first surface, the observer position, and theviewing angle; or if the first surface of the three-dimensional objectin the target space corresponds to a plurality of layers of illuminationinformation, the first surface is separately shaded based on theplurality of layers of illumination information corresponding to thefirst surface, the observer position, and the viewing angle, to obtainshading results respectively generated by the plurality of layers ofillumination information corresponding to the first surface underillumination of the any one light source; and a shading result of thefirst surface in the screen space under illumination of the any onelight source is obtained based on the shading results respectivelygenerated by the plurality of layers of illumination informationcorresponding to the first surface; or accumulation processing isperformed on the plurality of layers of illumination informationcorresponding to the first surface to obtain accumulated illuminationinformation corresponding to the first surface; and a shading result ofthe first surface in the screen space under illumination of the any onelight source is obtained based on the accumulated illuminationinformation corresponding to the first surface, the observer position,and the viewing angle.

The three-dimensional object is any three-dimensional object in thetarget space, and the first surface is any surface of thethree-dimensional object.

In this embodiment, under illumination of the any one light source ofthe current light sources, a group of illumination informationcorresponding to the first surface includes a layer of illuminationinformation. When the first surface corresponds to a layer ofillumination information, the terminal device obtains the shading resultof the first surface in the screen space based on the layer ofillumination information corresponding to the first surface, theobserver position, and the viewing angle. Specifically, a processingmethod for shading in ray tracing is as follows:

As shown in FIG. 12 , when determining a shading result of a positionpoint, a terminal device first determines a view matrix by using anobserver position, a viewing angle, and the like, then multiplies acoordinate in a world coordinate system by the view matrix, and convertsthe coordinate into a coordinate in an observer coordinate system (whichhas been described above and is not described herein again). Theterminal device obtains a viewing angle V, where V=position coordinateof eyes of an observer—position coordinate of a first position point ona first surface, and is represented as a vector from the first positionpoint to the observer position. It is assumed that the positioncoordinate of the eyes of the observer is (1, 1, 1), and the positioncoordinate of the first position point is (1, 0, 0), V=(1, 1, 1)−(1, 0,0)=(0, 1, 1). The position coordinates described herein are allrepresented in the observer coordinate system. V is standardized as aunit vector.

The terminal device reads, from the obtained illumination information, alayer of illumination information corresponding to the first surfaceunder illumination of the any one light source, where the layer ofillumination information includes an intensity and a direction of alight ray, and the direction is a direction in the foregoing x-y-zcoordinate system. A direction of a light ray at the first positionpoint is represented by M, and M is standardized as a unit vector.

The terminal device obtains an initial value of F0, where F0 is aFresnel reflectivity at 0 degree (Fresnel Reflectivity at 0 degree), F0is three-dimensional, and are respectively dimensions in an x direction,a y direction, and a z direction in the observer coordinate system. Forexample, the initial value of F0 is (0.04, 0.04, 0.04). The terminaldevice updates F0 based on a metallic and a given albedo of the firstposition point on the first surface, where updated F0=metallic of thefirst position point*albedo of the first position point+(1−metallic)*F0,and the albedo of the first position point is represented by R, and B.The metallic is one-dimensional.

The terminal device calculates a specular reflection factor, where thespecular reflection factor is related to roughness, F0, an includedangle θ between M and V, and the like, and the specular reflectionfactor is represented by KS, which is specifically:

KS=F0+(max(vec3(1.0−roughness),F0)−F0)*pow(1.0−cos θ,x)  (1)

In formula (1), F0 is the updated F0, and the roughness indicates aroughness degree of the first position point. vec3(1.0−roughness)indicates that 1.0−roughness is turned into a three-dimensional vector;max(vec3(1.0−roughness), F0) indicates that a maximum value ofvec3(1.0−roughness) and F0 is taken; pow(1.0−cos θ, x) indicates thatthe power of x of (1.0−cos θ) is calculated, and x is a preset value,for example, 5; cos θ=max(dot(M, V), 0.0), dot(M, V) indicates a dotproduct of M and V, and max(dot(M, V), 0.0) indicates that a maximumvalue of dot(M, V) and 0.0 is taken.

The terminal device calculates a diffuse reflection factor, where thediffuse reflection factor is represented by KD, a sum of diffusereflection and specular reflection is fixed, and when one is more, theother is less. KD is specifically:

KD=(1.0−KS)×(1.0−metallic of the first position point)  (2)

In formula (2), because KS is a three-dimensional vector, KD is also athree-dimensional vector.

Next, the terminal device calculates a specular reflection amount and adiffuse reflection amount of the first position point on the firstsurface:

For the first position point on the first surface, the terminal devicedetermines that the diffuse reflection amount of the first positionpoint is equal to a product of an intensity of a light ray of the firstposition point on the first surface and a reflectivity of the firstposition point, where the intensity may be represented by R, and B, andthe diffuse reflection amount of the first position point isthree-dimensional.

The terminal device determines that the specular reflection amount ofthe first position point is equal to the specular reflection factor.

The terminal device calculates that a color of the first position pointis equal to (diffuse reflection factor*diffuse reflection amount of thefirst position point+specular reflection amount of the first positionpoint)*value of the first position point at an ambient occlusion layer,and the color of the first position point represents a shading result ofthe first position point. The terminal device may determine a shadingresult of another position point on the first surface in a manner ofdetermining the shading result of the first position point. Herein, thecolor of the first position point is three-dimensional, that is, RGB.

In this description, “*” indicates multiplication.

This is merely a possible implementation. Another shading manner mayalso be applied to this embodiment of this application. Details are notdescribed herein again.

When the first surface corresponds to a plurality of layers ofillumination information, the terminal device performs shadingprocessing in the foregoing manner by using each layer of illuminationinformation, to obtain a shading result corresponding to each layer ofillumination information. Then, shading results corresponding to alllayers of illumination information of the first surface are added orfiltered, to obtain a shading result of the first surface. For example,the first surface corresponds to three layers of illuminationinformation, which are respectively A, B, and C. Shading processing maybe respectively performed by using A, B, and C, to obtain three shadingresults A1, B1, and C1 of the first surface. Then, the terminal deviceaccumulates the three shading results R=A1+B1+C1, to obtain a shadingresult R of the first surface.

Alternatively, when the first surface corresponds to a plurality oflayers of illumination information, the terminal device performssuperposition processing on the plurality of layers of illuminationinformation corresponding to the first surface, to obtain one layer ofaccumulated illumination information. The terminal device performsshading processing or filtering processing in the foregoing manner byusing the layer of accumulated illumination information, to obtain ashading result of the first surface. For example, the first surfacecorresponds to three layers of illumination information, which arerespectively A, B, and C. A, B, and C may be superposed to obtainaccumulated illumination information R (A, B, and C) of the firstsurface. Then, the terminal device performs shading processing once byusing R (A, B, and C), to obtain a shading result R of the firstsurface.

The foregoing provides only the shading result of the first surface. Asurface of each three-dimensional object is shaded in this manner, sothat a shading result of each surface of each three-dimensional objectin the target space can be obtained.

The foregoing is a shading process in ray tracing. A shading principleof Phong lighting is similar to a shading process of the ray tracing,and specific processing is as follows (herein also based on any onelight source in the current light sources):

The Phong lighting involves ambient lighting, diffuse reflectionlighting and specular lighting, and the like. The ambient lighting meansthat even in the dark, there is still some light in the world, so anobject is hardly completely dark. To simulate this, an ambient lightingconstant is used to always give the object a color. The diffusereflection lighting means that a directivity effect of a light source onan object is simulated. The specular lighting means that a bright spoton a surface of a glossy object is simulated.

1. Calculating the Ambient Lighting:

It is assumed that ambient light with at least a preset value directlyilluminates all surfaces of a three-dimensional object, and the presetvalue may be 10%. A color (that is, an intensity of a light source) ofthe light source in target space is multiplied by the preset value toobtain an ambient light component. Herein, the color of the light sourceis represented by RGB. That is, an ambient light component of eachposition point on each surface of the three-dimensional object is aproduct of the color of the light source and the preset value, and hasno direction. Herein, because the color of the light source isrepresented by RGB, an obtained ambient light component is alsorepresented by RGB. During calculation herein, a value of RGB maycorrespond to a corresponding value according to a specific formula. Theterminal device determines, based on ambient lighting, a shading resultof the ambient light for the three-dimensional object. Under the ambientlighting, a first color of a first position point is a result ofmultiplying an ambient light component of the first position point by analbedo of the first position point. Both the ambient light component andthe albedo of the first position point are three-dimensional, and eachdimension is correspondingly multiplied. For example, the ambient lightcomponent is (3, 3, 1), and the albedo of the first position point is(1, 1, 1), a result of multiplying the two is (3, 3, 1).

2. Calculating the Diffuse Reflection Lighting:

The terminal device obtains a color of the light source, positioninformation of the light source, and the like. The terminal deviceobtains a normal vector entering a first surface, where for a firstposition point on the first surface, the first surface is any surface ofa three-dimensional object, and the first position point is any positionpoint on the first surface. The terminal device determines that adiffuse reflection component of the first position point=diff*color ofthe light source, where the color of the light source is represented byRGB, diff=max(dot(first unit vector, second unit vector), 0.0),indicates that diff is a maximum value between a numerical value of adot product of the first unit vector and the second unit vector and 0.0.The first unit vector is a unit normal vector of the first surface; andthe second unit vector is equal to a unit vector in a direction in whichthe first position point points to a position of the light source. Inthis way, the diffuse reflection lighting of the first position pointcan be determined. The diffuse reflection lighting has no direction. Theterminal device may determine diffuse reflection lighting of anyposition point in this manner. Herein, when a value of dot(first unitvector, second unit vector) is less than 0, a value of diff is 0. Thisindicates that if an included angle between the first unit vector andthe second unit vector is greater than 90 degrees, impact of diffusereflection is 0. The terminal device determines, based on the diffusereflection lighting, shading of diffuse reflection light for thethree-dimensional object. Under the diffuse reflection lighting, asecond color of the first position point is a result of multiplying adiffuse reflection light component of the first position point by analbedo of the first position point. Both the diffuse reflection lightcomponent and the albedo of the first position point arethree-dimensional, and each dimension is correspondingly multiplied.

3. Calculating the Specular Lighting:

For the first position point on the first surface, the terminal devicedetermines a unit vector in a direction of a difference between theposition of the light source and the first position point, and theterminal device determines a reflected light component of specularlighting of the first position point, where the reflected lightcomponent includes a direction of the reflected light of the specularlighting. The direction of the reflected light of the specular lightingis: a reflection operation (—(a unit vector in a direction in which thefirst position point points to the position of the light source), (aunit normal vector of the first surface)). Herein, a reflected lightcomponent is a reflected light vector obtained by performing areflection operation on —(a unit vector in a direction in which thefirst position point points to the position of the light source) basedon the unit normal vector of the first surface, —(a unit vector in adirection in which the first position point points to the position ofthe light source) indicates a unit vector in a direction in which theposition of the light source points to the first position point. Becausethe reflected light leaves an object surface from the first positionpoint, and incident light arrives at the first position point from thelight source, a reflection operation needs to be performed in adirection opposite to a normal of the first surface, so that a correctdirection of the reflected light can be obtained.

The terminal device determines, based on the specular lighting, shadingof the specular reflection light for the three-dimensional object. Underthe specular reflection light, a third color of the first position pointis a product of a specular intensity of the first position point, areflection factor, a color of the any one light source, and the albedoof the first position point. The specular intensity reflects an amountof reflected light at the first position point. If the specularintensity is equal to a preset value, the reflection factor isrepresented by a formula: a formula of the reflection factor ispow(max(dot(viewDir, reflectDir), 0.0), a) (3).

In formula (3), viewDir represents a unit vector in a direction in whichthe first position point points to an observer position, reflectDirrepresents a reflected light component of specular lighting of the firstposition point in illumination information of a specular reflectionlayer, and is also a unit vector, dot(viewDir, reflectDir) represents adot product of viewDir and reflectDir, to obtain a cosine value of anincluded angle between viewDir and reflectDir, max(dot(viewDir,reflectDir), 0.0) represents a maximum value between dot(viewDir,reflectDir) and 0 is taken, and pow(max(dot(viewDir, reflectDir), 0.0),a) indicates that the power of a of max(dot(viewDir, reflectDir), 0.0)is taken, where a is a reflectivity, and is a preset value or is set bytarget space producer. Generally, a higher reflectivity of an objectindicates a stronger capability of reflecting light and less scattering.This processing process is a processing process performed in a worldcoordinate system. Both a color of the any one light source and thealbedo of the first position point are three-dimensional, and eachdimension is correspondingly multiplied.

Finally, the terminal device adds the first color, the second color, andthe third color to determine a final color of the first position point.

In a possible implementation, as described above, each layer ofillumination information of the plurality of layers of illuminationinformation included in the first group of illumination informationcorresponds to illumination information in different incident ranges orillumination information in different reflection ranges. A processingprocess in which the terminal device performs shading on eachthree-dimensional object in the target space in step 1003 is as follows:

For a target position point on the first surface of thethree-dimensional object, separately selecting, from a group ofillumination information corresponding to the first surface underillumination of each current light source, at least one layer ofillumination information closest to a viewing angle corresponding to thetarget position point; and performing shading processing on the targetposition point based on the at least one layer of illuminationinformation selected from each group of illumination information, theobserver position, and the viewing angle corresponding to the targetposition point.

In this embodiment, for a target position point on a first surface of athree-dimensional object, before shading is performed, a group ofillumination information corresponding to the first surface underillumination of each current light source is obtained. In each group ofillumination information, at least one layer of illumination informationclosest to a viewing angle corresponding to the target position point isselected. The closest herein refers to an endpoint whose viewing anglebelongs to a reflection range and/or is located in the reflection range.For example, the first surface is a plane, a viewing angle is 30degrees, and each layer of illumination information included in eachgroup of illumination information is illumination information in onereflection range. In each group of illumination information, a layer ofillumination information whose reflection range is 0 to 45 degrees isseparately selected. For another example, the first surface is a plane,a viewing angle is 30 degrees, each layer of illumination informationincluded in each group of illumination information is illuminationinformation having a number of bounces in one reflection range, andthere are three numbers of bounces. In each group of illuminationinformation, three layers of illumination information having threenumbers of bounces in a reflection range of 0 to 45 degrees areseparately selected. For another example, the first surface is a plane,a viewing angle is 45 degrees, and each layer of illuminationinformation included in each group of illumination information isillumination information in one reflection range. In each group ofillumination information, two layers of illumination information inreflection ranges of 0 to 45 degrees and 45 degrees to 90 degrees areseparately selected.

The terminal device performs shading processing on the target positionpoint by using the at least one layer of illumination informationselected from each group of illumination information, the observerposition, and the viewing angle corresponding to the target positionpoint. For a specific shading process, refer to a shading process of thefirst position point. Details are not described herein again.

In this way, illumination information can be dynamically selected, andthe three-dimensional object can be dynamically rendered in real time.

It should be noted that, if each layer of illumination informationincluded in the first group of illumination information corresponds toillumination information in different incident ranges, when at least onelayer of illumination information closest to the viewing anglecorresponding to the target position point is selected, an incidentrange first needs to be converted into a reflection range. According tothe foregoing processing of the reflection range, the at least one layerof illumination information closest to the viewing angle correspondingto the target position point is selected.

It should be further noted that, because of different position points ona same surface, a viewing angle may be different. When each layer ofillumination information corresponds to illumination information indifferent incident ranges, different layers of illumination informationmay be obtained for different position points on a same surface.

In addition, in this embodiment of this application, a processingprocess of performing shading based on a reflectivity of a targetsurface is further provided:

In this embodiment of this application, a process in which a terminaldevice performs three-dimensional shading in screen space is furtherprovided.

At least one group of illumination information corresponding to eachsurface of a three-dimensional object in target space under illuminationof at least one light source is obtained, where for any surface, a firstgroup of illumination information corresponding to the surface includesone or more layers of illumination information, and the one or morelayers of illumination information reflect illumination information ofeach position point on the surface under illumination of a light sourceto which the first group of illumination information belongs;illumination information corresponding to each surface of thethree-dimensional object under illumination of a current light source isdetermined in the at least one group of illumination information; andshading processing is performed on the three-dimensional object in thescreen space based on the illumination information corresponding to eachsurface of the three-dimensional object under illumination of thecurrent light source and a reflectivity of each surface.

In this embodiment, the at least one group of illumination informationcorresponding to each surface of the three-dimensional object underillumination of the at least one light source is obtained. Theillumination information corresponding to each surface of thethree-dimensional object under illumination of the current light sourceis determined. For any surface of the three-dimensional object, areflectivity of the surface is obtained. A value relationship betweenthe reflectivity of the surface and a preset value is determined, and ifthe reflectivity of the surface is less than the preset value, shadingprocessing is performed on the surface in material space based on theillumination information corresponding to the surface under illuminationof the current light source, to obtain a material shading result. Forexample, for a surface, all layers of illumination information of thesurface are superposed, and then shading is performed, or shading isseparately performed by using each layer of illumination information ofthe surface, and shading results corresponding to all layers ofillumination information are finally superposed. Then, secondaryrendering is performed on the material shading result of the surface,and shading is performed in screen space. Herein, the material space istwo-dimensional space, and is generally represented by two coordinatevalues uv. In addition, a mapping coordinate is corresponded, indicatingthat a coordinate of the two-dimensional material space inthree-dimensional space. The secondary rendering herein refers tocasting the material shading result of the surface to two-dimensionalscreen space.

If the reflectivity of the surface is greater than or equal to thepreset value, the observer position and the viewing angle of theobserver are obtained; and shading processing is performed on thesurface in the screen space based on the illumination informationcorresponding to the surface under illumination of the current lightsource, the observer position, and the viewing angle. For thisprocessing, refer to the foregoing description. Details are notdescribed herein again.

The preset value herein is small. When the reflectivity of the surfaceis low, it indicates that the position of the observer and the viewingangle of the observer do not affect the shading result. Therefore, thematerial shading result may be first obtained, and then rendering isperformed in the screen space.

In this way, according to this embodiment of this application, powerconsumption of a terminal device can be saved in a plurality ofscenarios requiring rendering. For example, this embodiment of thisapplication is applied to a game rendering scenario, and terminaldevices of different users in a same scenario in a shared game all needto be rendered. Therefore, shading needs to be performed, that is,illumination information is calculated. By using the solution in thisembodiment of this application, the server provides the illuminationinformation for a terminal device of each user in the shared game. Theterminal devices of different users may use the illumination informationfor performing shading on the scenario based on the observer positionand the viewing angle of the user, and the illumination information doesnot need to be calculated. In addition, the server only needs tocalculate the illumination information once, and therefore, acalculation amount of the shading device can be saved. In addition,because the illumination information is obtained by actual calculation,rendering quality of the scenario is not affected.

In addition, in this embodiment of this application, an architecture ofbaking may be further provided. On an apparatus with limited computingpower, illumination information may be processed offline in advance andstored (for example, stored at a material layer). The terminal devicemay perform shading processing on a scenario based on the illuminationinformation obtained offline in advance, to implement high-qualityrendering.

FIG. 13 is a structural diagram of a three-dimensional shading apparatusaccording to an embodiment of this application. The apparatus may beimplemented as a part of the apparatus or the entire apparatus by usingsoftware, hardware, or a combination thereof. The apparatus provided inthis embodiment of this application may implement the proceduredescribed in FIG. 2 in embodiments of this application. The apparatusincludes an obtaining module 1110, a determining module 1120, and aproviding module 1130.

The obtaining module 1110 is configured to obtain position informationand an intensity of at least one light source in target space, and maybe specifically configured to implement an obtaining function in step201 and perform an implicit step included in step 201.

The determining module 1120 is configured to determine, based on theposition information and the intensity of the at least one light source,at least one group of illumination information corresponding to eachsurface of a three-dimensional object in the target space underillumination of the at least one light source, where for any surface, afirst group of illumination information corresponding to the surfaceincludes one or more layers of illumination information, and the one ormore layers of illumination information reflect illumination informationof each position point on the surface under illumination of a lightsource to which the first group of illumination information belongs, andmay be specifically configured to implement a determining function instep 202 and perform an implicit step included in step 202.

The providing module 1130 is configured to provide the at least onegroup of illumination information for a device that performs shadingprocessing on the target space, and may be specifically configured toimplement a providing function in step 203 and perform an implicit stepincluded in step 203.

In a possible implementation, the obtaining module 1110 is furtherconfigured to:

obtain light ray information of the light source, where the light rayinformation includes a quantity of light rays and a light direction.

The determining module 1120 is configured to:

determine scattering information of each surface of thethree-dimensional object in the target space with a light ray of the atleast one light source based on the intensity, the position information,and the light ray information of the at least one light source; anddetermine, based on the scattering information of each surface of thethree-dimensional object, the at least one group of illuminationinformation corresponding to each surface of the three-dimensionalobject under illumination of the at least one light source.

In a possible implementation, the determining module 1120 is configuredto:

separately superpose, for a first surface of the three-dimensionalobject in the target space, intensities and directions of light raysthat have a same number of bounces and that are in scatteringinformation corresponding to the first surface under illumination of atarget light source in the at least one light source, to obtain asuperposition intensity and a superposition direction of rays of eachnumber of bounces and corresponding to the first surface; and

determine, based on the superposition intensity and the superpositiondirection of the rays of each number of bounces, a group of illuminationinformation corresponding to the first surface under illumination of thetarget light source.

In a possible implementation, an intensity and a direction of a lightray in the scattering information corresponding to the first surfaceunder illumination of the target light source are respectively anincident intensity and an incident direction of a light ray incident tothe first surface; or

an intensity and a direction of a light ray in the scatteringinformation corresponding to the first surface under illumination of thetarget light source are respectively a reflection intensity and areflection direction of a light ray reflected from the first surface.

In a possible implementation, the determining module 1120 is configuredto:

for a first surface of the three-dimensional object, determine, inscattering information corresponding to the first surface underillumination of a target light source, an intensity and a direction of alight ray that belongs to each incident range and that is in light raysincident to each position point on the first surface; and determine,based on a superposition intensity and a superposition direction of thelight ray that is in each incident range and that corresponds to eachposition point, a group of illumination information corresponding to thefirst surface under illumination of the target light source; or

for a first surface of the three-dimensional object, determine, inscattering information corresponding to the first surface underillumination of a target light source, an intensity and a direction of alight ray that belongs to each reflection range and that is in lightrays reflected from each position point on the first surface; anddetermine, based on a superposition intensity and a superpositiondirection of the light ray that is in each reflection range and thatcorresponds to each position point, a group of illumination informationcorresponding to the first surface under illumination of the targetlight source.

In this embodiment of this application, division into modules is anexample, and is merely logical function division and may be anotherdivision manner in actual implementation. In addition, each functionalmodule in embodiments of this application may be integrated into oneprocessor, or may exist alone physically, or two or more modules may beintegrated into one module. The integrated module may be implemented ina form of hardware, or may be implemented in a form of a softwarefunctional module.

FIG. 14 is a structural diagram of a three-dimensional shading apparatusaccording to an embodiment of this application. The apparatus may beimplemented as a part of the apparatus or the entire apparatus by usingsoftware, hardware, or a combination thereof. The apparatus provided inthis embodiment of this application may implement the proceduredescribed in FIG. 10 in embodiments of this application. The apparatusincludes an obtaining module 1210 and a shading module 1220.

The obtaining module 1210 is configured to:

obtain at least one group of illumination information corresponding toeach surface of a three-dimensional object in target space underillumination of at least one light source, where for any surface, afirst group of illumination information corresponding to the surfaceincludes one or more layers of illumination information, and the one ormore layers of illumination information reflect illumination informationof each position point on the surface under illumination of a lightsource to which the first group of illumination information belongs; and

obtain an observer position and a viewing angle of an observer, and maybe specifically configured to implement an obtaining function in step801 and step 802 and perform an implicit step included in step 801 andstep 802.

The shading module 1220 is configured to perform, in screen space,shading processing on the three-dimensional object in the target spacebased on illumination information corresponding to each surface of thethree-dimensional object in the target space under illumination of acurrent light source, the observer position, and the viewing angle, andmay be specifically configured to implement a shading function in step803 and perform an implicit step included in step 803.

In a possible implementation, the shading module 1220 is configured to:

if there are a plurality of the current light sources, separatelyperform, under illumination of any one light source of the current lightsources, shading processing on each surface of the three-dimensionalobject based on illumination information corresponding to each surfaceof the three-dimensional object under illumination of the light source,the observer position, and the viewing angle, to obtain a shading resultof each surface of the three-dimensional object in the screen spaceunder illumination of the light source; and

accumulate shading results of each surface of the three-dimensionalobject in the screen space under illumination of the current lightsources, to obtain a total shading result of each surface of thethree-dimensional object in the screen space.

In a possible implementation, the shading module 1220 is configured to:

under illumination of any one light source of the current light sources,if a first surface of the three-dimensional object in the target spacecorresponds to one layer of illumination information, obtain, based onthe layer of illumination information corresponding to the firstsurface, the observer position, and the viewing angle, a shading resultof the first surface in the screen space under illumination of the lightsource; and

if the first surface of the three-dimensional object corresponds to aplurality of layers of illumination information, separately shade thefirst surface based on the plurality of layers of illuminationinformation corresponding to the first surface, the observer position,and the viewing angle, to obtain shading results respectively generatedby the plurality of layers of illumination information corresponding tothe first surface under illumination of the light source; and obtain ashading result of the first surface in the screen space underillumination of the light source based on the shading resultsrespectively generated by the plurality of layers of illuminationinformation corresponding to the first surface; or perform accumulationprocessing on the plurality of layers of illumination informationcorresponding to the first surface to obtain accumulated illuminationinformation corresponding to the first surface; and obtain a shadingresult of the first surface in the screen space under illumination ofthe light source based on the accumulated illumination informationcorresponding to the first surface, the observer position, and theviewing angle.

In a possible implementation, each layer of illumination information ofthe plurality of layers of illumination information included in thefirst group of illumination information corresponds to illuminationinformation in different incident ranges or illumination information indifferent reflection ranges.

The shading module 1220 is configured to:

for a target position point on the first surface of thethree-dimensional object, separately select, from a group ofillumination information corresponding to the first surface underillumination of each current light source, at least one layer ofillumination information closest to a viewing angle corresponding to thetarget position point; and

perform shading processing on the target position point in the screenspace based on the at least one layer of illumination informationselected from each group of illumination information, the observerposition, and the viewing angle corresponding to the target positionpoint.

In a possible implementation, the shading module 1220 is configured to:

perform shading processing on the three-dimensional object in the screenspace based on the illumination information corresponding to eachsurface of the three-dimensional object under illumination of thecurrent light source and a reflectivity of each surface.

In a possible implementation, the obtaining module 1210 is configuredto:

receive the at least one group of illumination information thatcorresponds to each surface of the three-dimensional object in thetarget space under illumination of the at least one light source andthat is sent by a server; or

determine the at least one group of illumination informationcorresponding to each surface of the three-dimensional object in thetarget space under illumination of the at least one light source.

FIG. 14 is a structural diagram of a three-dimensional shading apparatusaccording to an embodiment of this application. The apparatus may beimplemented as a part of the apparatus or the entire apparatus by usingsoftware, hardware, or a combination thereof. The apparatus provided inthis embodiment of this application may implement a shading procedure inthis embodiment of this application. The apparatus includes an obtainingmodule 1210 and a shading module 1220.

The obtaining module 1210 is configured to obtain at least one group ofillumination information corresponding to each surface of athree-dimensional object in target space under illumination of at leastone light source, where for any surface, a first group of illuminationinformation corresponding to the surface includes one or more layers ofillumination information, and the one or more layers of illuminationinformation reflect illumination information of each position point onthe surface under illumination of a light source to which the firstgroup of illumination information belongs.

The shading module 1220 is configured to:

determine, in the at least one group of illumination information,illumination information corresponding to each surface of thethree-dimensional object under illumination of a current light source;and

perform shading processing on the three-dimensional object in screenspace based on the illumination information corresponding to eachsurface of the three-dimensional object under illumination of thecurrent light source and a reflectivity of each surface.

In this embodiment of this application, division into modules is anexample, and is merely logical function division and may be anotherdivision manner in actual implementation. In addition, each functionalmodule in embodiments of this application may be integrated into oneprocessor, or may exist alone physically, or two or more modules may beintegrated into one module. The integrated module may be implemented ina form of hardware, or may be implemented in a form of a softwarefunctional module.

All or a part of the foregoing embodiments may be implemented bysoftware, hardware, firmware, or any combination thereof. When thesoftware is used for implementation, all or a part of the foregoingembodiments may be implemented in a form of a computer program product.The computer program product includes one or more computer instructions.When the computer program instructions are loaded and executed on aserver or a terminal, all or some of the procedures or functionsaccording to embodiments of this application are generated. The computerinstructions may be stored in a computer-readable storage medium or maybe transmitted from a computer-readable storage medium to anothercomputer-readable storage medium. For example, the computer instructionsmay be transmitted from a website, computer, server, or data center toanother web site, computer, server, or data center in a wired (forexample, a coaxial optical cable, an optical fiber, or a digitalsubscriber line) or wireless (for example, infrared, radio, ormicrowave) manner. The computer-readable storage medium may be anyusable medium accessible to a server or a terminal, or a data storagedevice, such as a server or a data center, integrating one or moreusable media. The usable media may be a magnetic medium (for example, afloppy disk, a hard disk drive, or a magnetic tape), an optical medium(for example, a digital video disk (Digital Video Disk, DVD)), or asemiconductor medium (for example, a solid-state drive).

1. A three-dimensional shading method performed by a computing device,the method comprising: obtaining position information and intensity of alight source in a target space; determining, based on the positioninformation and the intensity of the light source, a group ofillumination information data corresponding to each surface of multiplesurfaces of a three-dimensional object in the target space underillumination of the light source, wherein the group of illuminationinformation data corresponding to said each surface comprises layers ofillumination information data reflecting illumination information ofeach position point on said each surface under illumination of the lightsource; and providing the groups of illumination information datacorresponding to the multiple surfaces of the three-dimensional objectto a device that performs shading processing on the target space.
 2. Themethod according to claim 1, further comprising: obtaining light rayinformation of the light source, wherein the light ray informationcomprises information regarding a quantity of light rays and a lightdirection; and wherein the step of determining the group of illustrationinformation data corresponding to each surface comprises: determiningscattering information of each of the multiple surfaces of thethree-dimensional object in the target space with a light ray of thelight source based on the intensity, the position information, and thelight ray information of the light source; and determining, based on thescattering information of the multiple surfaces of the three-dimensionalobject, the group of illumination information data corresponding to saideach surface of the three-dimensional object under illumination of thelight source.
 3. The method according to claim 2, wherein the step ofdetermining based on the scattering information comprises: separatelysuperposing, for a first surface of the three-dimensional object in thetarget space, intensities and directions of light rays that have a samenumber of bounces and are in the scattering information corresponding tothe first surface under illumination of a target light source in thelight source, to obtain a superposition intensity and a superpositiondirection of rays of each number of bounces and corresponding to thefirst surface; and determining, based on the superposition intensity andthe superposition direction of the rays of each number of bounces, thegroup of illumination information data corresponding to the firstsurface under illumination of the target light source.
 4. The methodaccording to claim 3, wherein an intensity and a direction of a lightray in the scattering information corresponding to the first surfaceunder illumination of the target light source are respectively anincident intensity and an incident direction of a light ray incident tothe first surface, or an intensity and a direction of a light ray in thescattering information corresponding to the first surface underillumination of the target light source are respectively a reflectionintensity and a reflection direction of a light ray reflected from thefirst surface.
 5. The method according to claim 2, wherein the step ofdetermining based on the scattering information comprises: for a firstsurface of the three-dimensional object, determining, in scatteringinformation corresponding to the first surface under illumination of atarget light source, an intensity and a direction of a light ray thatbelongs to each incident range and is in light rays incident to eachposition point; and determining, based on a superposition intensity anda superposition direction of the light ray that is in each incidentrange and that corresponds to each position point, a group ofillumination information data corresponding to the first surface underillumination of the target light source.
 6. The method according toclaim 2, wherein the step of determining based on the scatteringinformation comprises: for a first surface of the three-dimensionalobject, determining, in scattering information corresponding to thefirst surface under illumination of a target light source, an intensityand a direction of a light ray that belongs to each reflection range andthat is in light rays reflected from each position point; anddetermining, based on a superposition intensity and a superpositiondirection of the light ray that is in each reflection range and thatcorresponds to each position point, the group of illuminationinformation data corresponding to the first surface under illuminationof the target light source.
 7. A three-dimensional shading methodperformed by a computing device, the method comprising: obtaining agroup of illumination information data corresponding to each surface ofmultiple surfaces of a three-dimensional object in target space underillumination of a light source, wherein for said each surface, the groupof illumination information data corresponding to said each surfacecomprises layers of illumination information, and the layers ofillumination information reflect illumination information of eachposition point on said each surface under illumination of the lightsource to which the group of illumination information data belongs;obtaining an observer position and a viewing angle of an observer; andperforming, in a screen space, shading processing on thethree-dimensional object in the target space based on illuminationinformation corresponding to the multiple surfaces of thethree-dimensional object in the target space under illumination of acurrent light source, the observer position, and the viewing angle. 8.The method according to claim 7, wherein there is a plurality of currentlight sources, and wherein the step of performing shading processing inthe screen space comprises: separately performing, under illumination ofeach current light source of the plurality of current light sources,shading processing on each surface of the three-dimensional object basedon illumination information corresponding to the multiple surfaces ofthe three-dimensional object under illumination of said each currentlight source, the observer position, and the viewing angle, to obtain ashading result of said each surface of the three-dimensional object inthe screen space under illumination of said each current light source;and accumulating shading results of the multiple surfaces of thethree-dimensional object in the screen space under illumination of thecurrent light sources, to obtain a total shading result of said eachsurface of the three-dimensional object in the screen space.
 9. Themethod according to claim 8, wherein the step of separately performingshading processing on each surface of the three-dimensional objectcomprises: under illumination of each current light source of thecurrent light sources, when a first surface of the three-dimensionalobject in the target space corresponds to one layer of illuminationinformation, obtaining, based on the layer of illumination informationcorresponding to the first surface, the observer position, and theviewing angle, a shading result of the first surface in the screen spaceunder illumination of the current light source.
 10. The method accordingto claim 8, wherein the step of separately performing shading processingon each surface of the three-dimensional object comprises: underillumination of a current light source of the current light sources,when a first surface of the three-dimensional object corresponds to aplurality of layers of illumination information, separately shading thefirst surface based on the plurality of layers of illuminationinformation corresponding to the first surface, the observer position,and the viewing angle, to obtain shading results respectively generatedby the plurality of layers of illumination information corresponding tothe first surface under illumination of the current light source; andobtaining a shading result of the first surface in the screen spaceunder illumination of the current light source based on the shadingresults respectively generated by the plurality of layers ofillumination information corresponding to the first surface; orperforming accumulation processing on the plurality of layers ofillumination information corresponding to the first surface to obtainaccumulated illumination information corresponding to the first surface;and obtaining a shading result of the first surface in the screen spaceunder illumination of the current light source based on the accumulatedillumination information corresponding to the first surface, theobserver position, and the viewing angle.
 11. The method according toclaim 6, wherein each layer of illumination information of the pluralityof layers of illumination information of the group of illuminationinformation data corresponds to illumination information in differentincident ranges or illumination information in different reflectionranges, wherein the step of performing in the screen space shadingprocessing on the three-dimensional object in the target spacecomprises: for a target position point on the first surface of thethree-dimensional object, separately selecting, from the group ofillumination information data corresponding to the first surface underillumination of a current light source, a layer of illuminationinformation closest to a viewing angle corresponding to the targetposition point; and performing shading processing on the target positionpoint in the screen space based on the layer of illumination informationselected from the group of illumination information data, the observerposition, and the viewing angle corresponding to the target positionpoint.
 12. A three-dimensional shading apparatus comprising: aprocessor; and a memory storing executable instructions; and a processorconfigured to execute the executable instructions to: obtain positioninformation and intensity of a light source in target space; determine,based on the position information and the intensity of the light source,a group of illumination information data corresponding to each surfaceof multiple surfaces of a three-dimensional object in the target spaceunder illumination of the at least one light source, wherein the groupof illumination information data corresponding to said each surfacecomprises layers of illumination information, and the layers ofillumination information reflect illumination information of eachposition point on said each surface under illumination of the lightsource to which the first group of illumination information databelongs; and provide the groups of illumination information data for themultiple surfaces of the three-dimensional object to a device thatperforms shading processing on the target space.
 13. The apparatusaccording to claim 12, wherein the apparatus is further configured to:obtain light ray information of the light source, wherein the light rayinformation comprises a quantity of light rays and a light direction;and determine scattering information of each of the multiple surfaces ofthe three-dimensional object in the target space with a light ray of thelight source based on the intensity, the position information, and thelight ray information of the one light source; and determine, based onthe scattering information of the multiple surfaces of thethree-dimensional object, the group of illumination information datacorresponding to each surface of the three-dimensional object underillumination of the light source.
 14. The apparatus according to claim13, wherein the apparatus is configured to determine based on thescattering by: separately superposing, for a first surface of thethree-dimensional object in the target space, intensities and directionsof light rays that have a same number of bounces and that are inscattering information corresponding to the first surface underillumination of a target light source in the at least one light source,to obtain a superposition intensity and a superposition direction of aray of each number of bounces and corresponding to the first surface;and determining, based on the superposition intensity and thesuperposition direction of the rays with each number of bounces, a groupof illumination information data corresponding to the first surfaceunder illumination of the target light source.
 15. The apparatusaccording to claim 14, wherein an intensity and a direction of a lightray in the scattering information corresponding to the first surfaceunder illumination of the target light source are respectively anincident intensity and an incident direction of a light ray incident tothe first surface; or an intensity and a direction of a light ray in thescattering information corresponding to the first surface underillumination of the target light source are respectively a reflectionintensity and a reflection direction of a light ray reflected from thefirst surface.
 16. The apparatus according to claim 13, wherein theapparatus is configured to determine the group of illuminationinformation data based on the scattering information by: for a firstsurface of the three-dimensional object, determining, in scatteringinformation corresponding to the first surface under illumination of atarget light source, an intensity and a direction of a light ray thatbelongs to each incident range and that is in light rays incident toeach position point; and determine, based on a superposition intensityand a superposition direction of the light ray that is in each incidentrange and that corresponds to each position point on the first surface,a group of illumination information data corresponding to the firstsurface under illumination of the target light source.
 17. The apparatusaccording to claim 13, wherein the apparatus is configured to determinethe group of illumination information data based on the scatteringinformation by: for a first surface of the three-dimensional object,determining, in scattering information corresponding to the firstsurface under illumination of a target light source, an intensity and adirection of a light ray that belongs to each reflection range and thatis in light rays reflected from each position point; and determining,based on a superposition intensity and a superposition direction of thelight ray that is in each reflection range and that corresponds to eachposition point on the first surface, a group of illumination informationdata corresponding to the first surface under illumination of the targetlight source.
 18. A three-dimensional shading apparatus comprising: amemory storing executable instructions; and a processor configured toexecute the executable instructions to: obtain a group of illuminationinformation data corresponding to each surface of multiple surfaces of athree-dimensional object in target space under illumination of at leastone light source, wherein the group of illumination information datacorresponding to the surface comprises layers of illuminationinformation, and the layers of illumination information reflectillumination information of each position point on said each surfaceunder illumination of the light source to which the first group ofillumination information data belongs; and obtain an observer positionand a viewing angle of an observer; and perform, in a screen space,shading processing on the three-dimensional object in the target spacebased on illumination information corresponding to the multiple surfacesof the three-dimensional object in the target space under illuminationof a current light source, the observer position, and the viewing angle.19. The apparatus according to claim 18, wherein there is a plurality ofcurrent light sources, and wherein the apparatus is configured toperform shading processing in the screen space by: separatelyperforming, under illumination of each current light source of theplurality of current light sources, shading processing on each surfaceof the three-dimensional object based on illumination informationcorresponding to the multiple surfaces of the three-dimensional objectunder illumination of said each current light source, the observerposition, and the viewing angle, to obtain a shading result of said eachsurface of the three-dimensional object in the screen space underillumination of said each current light source; and accumulating shadingresults the multiple surfaces of the three-dimensional object in thescreen space under illumination of the current light sources, to obtaina total shading result of each surface of the three-dimensional objectin the screen space.
 20. The apparatus according to claim 18, whereineach layer of illumination information of the plurality of layers ofillumination information comprised in the group of illuminationinformation data corresponds to illumination information in differentincident ranges or illumination information in different reflectionranges, and the processor is configured to perform shading processing inthe screen space by: for a target position point on the first surface ofthe three-dimensional object, separately selecting, from a group ofillumination information data corresponding to the first surface underillumination of each current light source, a layer of illuminationinformation closest to a viewing angle corresponding to the targetposition point; and performing shading processing on the target positionpoint in the screen space based on the layer of illumination informationselected from the group of illumination information data, the observerposition, and the viewing angle corresponding to the target positionpoint.